From 8163af217e586714b484f70bd1993b4dfb4b958b Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 1 May 2021 22:51:58 -0400 Subject: [PATCH] Option to search series type in library Works like a tag so "-Manga" for example excludes manga --- .../eu/kanade/tachiyomi/data/database/models/Manga.kt | 8 ++++---- .../java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt | 10 ++++++---- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index 1f72ec81ee..9a59be0966 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -54,9 +54,9 @@ interface Manga : SManga { 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( - when (seriesType()) { + when (seriesType(sourceManager = sourceManager)) { TYPE_WEBTOON -> R.string.webtoon TYPE_MANHWA -> R.string.manhwa TYPE_MANHUA -> R.string.manhua @@ -79,8 +79,8 @@ interface Manga : SManga { /** * The type of comic the manga is (ie. manga, manhwa, manhua) */ - fun seriesType(useOriginalTags: Boolean = false, customTags: String? = null): Int { - val sourceName = Injekt.get().getOrStub(source).name + fun seriesType(useOriginalTags: Boolean = false, customTags: String? = null, sourceManager: SourceManager? = null): Int { + val sourceName by lazy { (sourceManager ?: Injekt.get()).getOrStub(source).name } val tags = customTags ?: if (useOriginalTags) originalGenre else genre val currentTags = tags?.split(",")?.map { it.trim().toLowerCase(Locale.US) } ?: emptyList() return if (currentTags.any { tag -> isMangaTag(tag) }) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 6b60468173..944dc6e88d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.library -import android.annotation.SuppressLint import android.view.Gravity import android.view.View import android.view.ViewGroup @@ -36,6 +35,7 @@ class LibraryItem( var downloadCount = -1 var unreadType = 2 + private val sourceManager: SourceManager by injectLazy() private val uniformSize: Boolean get() = preferences.uniformGrid().get() @@ -160,16 +160,18 @@ class LibraryItem( } else containsGenre(constraint, manga.genre?.split(", ")) } - @SuppressLint("DefaultLocale") private fun containsGenre(tag: String, genres: List?): Boolean { if (tag.trim().isEmpty()) return true return if (tag.startsWith("-")) { 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 } else { genres?.find { - it.trim().equals(tag, ignoreCase = true) + it.trim().equals(tag, ignoreCase = true) || + manga.seriesType(preferences.context, sourceManager).equals(tag, true) } != null } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 3a4bf1135a..6968d4e010 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -286,9 +286,9 @@ class LibraryPresenter( if (filterMangaType > 0) { 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 { - filterMangaType != item.manga.seriesType() + filterMangaType != item.manga.seriesType(sourceManager = sourceManager) } ) return false }