Option to search series type in library

Works like a tag so "-Manga" for example excludes manga
This commit is contained in:
Jays2Kings 2021-05-01 22:51:58 -04:00
parent 1ab54487d1
commit 8163af217e
3 changed files with 12 additions and 10 deletions

View File

@ -54,9 +54,9 @@ interface Manga : SManga {
fun showChapterTitle(defaultShow: Boolean): Boolean = chapter_flags and DISPLAY_MASK == DISPLAY_NUMBER fun showChapterTitle(defaultShow: Boolean): Boolean = chapter_flags and DISPLAY_MASK == DISPLAY_NUMBER
fun seriesType(context: Context): String { fun seriesType(context: Context, sourceManager: SourceManager? = null): String {
return context.getString( return context.getString(
when (seriesType()) { when (seriesType(sourceManager = sourceManager)) {
TYPE_WEBTOON -> R.string.webtoon TYPE_WEBTOON -> R.string.webtoon
TYPE_MANHWA -> R.string.manhwa TYPE_MANHWA -> R.string.manhwa
TYPE_MANHUA -> R.string.manhua TYPE_MANHUA -> R.string.manhua
@ -79,8 +79,8 @@ interface Manga : SManga {
/** /**
* The type of comic the manga is (ie. manga, manhwa, manhua) * The type of comic the manga is (ie. manga, manhwa, manhua)
*/ */
fun seriesType(useOriginalTags: Boolean = false, customTags: String? = null): Int { fun seriesType(useOriginalTags: Boolean = false, customTags: String? = null, sourceManager: SourceManager? = null): Int {
val sourceName = Injekt.get<SourceManager>().getOrStub(source).name val sourceName by lazy { (sourceManager ?: Injekt.get()).getOrStub(source).name }
val tags = customTags ?: if (useOriginalTags) originalGenre else genre val tags = customTags ?: if (useOriginalTags) originalGenre else genre
val currentTags = tags?.split(",")?.map { it.trim().toLowerCase(Locale.US) } ?: emptyList() val currentTags = tags?.split(",")?.map { it.trim().toLowerCase(Locale.US) } ?: emptyList()
return if (currentTags.any { tag -> isMangaTag(tag) }) { return if (currentTags.any { tag -> isMangaTag(tag) }) {

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.tachiyomi.ui.library
import android.annotation.SuppressLint
import android.view.Gravity import android.view.Gravity
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -36,6 +35,7 @@ class LibraryItem(
var downloadCount = -1 var downloadCount = -1
var unreadType = 2 var unreadType = 2
private val sourceManager: SourceManager by injectLazy()
private val uniformSize: Boolean private val uniformSize: Boolean
get() = preferences.uniformGrid().get() get() = preferences.uniformGrid().get()
@ -160,16 +160,18 @@ class LibraryItem(
} else containsGenre(constraint, manga.genre?.split(", ")) } else containsGenre(constraint, manga.genre?.split(", "))
} }
@SuppressLint("DefaultLocale")
private fun containsGenre(tag: String, genres: List<String>?): Boolean { private fun containsGenre(tag: String, genres: List<String>?): Boolean {
if (tag.trim().isEmpty()) return true if (tag.trim().isEmpty()) return true
return if (tag.startsWith("-")) { return if (tag.startsWith("-")) {
genres?.find { genres?.find {
it.trim().equals(tag.substringAfter("-"), ignoreCase = true) val realTag = tag.substringAfter("-")
it.trim().equals(realTag, ignoreCase = true) ||
manga.seriesType(preferences.context, sourceManager).equals(realTag, true)
} == null } == null
} else { } else {
genres?.find { genres?.find {
it.trim().equals(tag, ignoreCase = true) it.trim().equals(tag, ignoreCase = true) ||
manga.seriesType(preferences.context, sourceManager).equals(tag, true)
} != null } != null
} }
} }

View File

@ -286,9 +286,9 @@ class LibraryPresenter(
if (filterMangaType > 0) { if (filterMangaType > 0) {
if (if (filterMangaType == Manga.TYPE_MANHWA) { if (if (filterMangaType == Manga.TYPE_MANHWA) {
(filterMangaType != item.manga.seriesType() && filterMangaType != Manga.TYPE_WEBTOON) (filterMangaType != item.manga.seriesType(sourceManager = sourceManager) && filterMangaType != Manga.TYPE_WEBTOON)
} else { } else {
filterMangaType != item.manga.seriesType() filterMangaType != item.manga.seriesType(sourceManager = sourceManager)
} }
) return false ) return false
} }