From bd748f6a62749db0fc009a2f0d67f8843ad32aa7 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 21 May 2020 14:00:55 -0400 Subject: [PATCH] Skip filtered chapters while reading --- .../data/preference/PreferenceKeys.kt | 2 + .../data/preference/PreferencesHelper.kt | 2 + .../tachiyomi/ui/reader/ReaderPresenter.kt | 40 +++++++++++++++++-- .../ui/setting/SettingsReaderController.kt | 5 +++ .../main/res/layout/reader_chapters_sheet.xml | 4 +- app/src/main/res/values/strings.xml | 1 + 6 files changed, 49 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 38d685214c..38bdb30055 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -129,6 +129,8 @@ object PreferenceKeys { const val skipRead = "skip_read" + const val skipFiltered = "skip_filtered" + const val downloadBadge = "display_download_badge" const val useBiometrics = "use_biometrics" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 7c097cbd49..71617fc963 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -219,6 +219,8 @@ class PreferencesHelper(val context: Context) { fun skipRead() = prefs.getBoolean(Keys.skipRead, false) + fun skipFiltered() = prefs.getBoolean(Keys.skipFiltered, true) + fun useBiometrics() = rxPrefs.getBoolean(Keys.useBiometrics, false) fun lockAfter() = rxPrefs.getInteger(Keys.lockAfter, 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 551a73ea04..28192cae69 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -96,8 +96,29 @@ class ReaderPresenter( ?: error("Requested chapter of id $chapterId not found in chapter list") val chaptersForReader = - if (preferences.skipRead()) { - val list = dbChapters.filter { !it.read }.toMutableList() + if (preferences.skipRead() || preferences.skipFiltered()) { + val list = dbChapters + .filter { + if (preferences.skipRead() && it.read) { + return@filter false + } else if (preferences.skipFiltered()) { + if ( + (manga.readFilter == Manga.SHOW_READ && !it.read) || + (manga.readFilter == Manga.SHOW_UNREAD && it.read) || + ( + manga.downloadedFilter == Manga.SHOW_DOWNLOADED && + !downloadManager.isChapterDownloaded(it, manga) + ) || + (manga.bookmarkedFilter == Manga.SHOW_BOOKMARKED && !it.bookmark) + ) { + return@filter false + } + } + + true + } + .toMutableList() + val find = list.find { it.id == chapterId } if (find == null) { list.add(selectedChapter) @@ -189,7 +210,20 @@ class ReaderPresenter( suspend fun getChapters(): List { val manga = manga ?: return emptyList() chapterItems = withContext(Dispatchers.IO) { - val list = db.getChapters(manga).executeOnIO().sortedBy { + val list = db.getChapters(manga).executeOnIO().filter { + if (preferences.skipFiltered()) { + if ((manga.readFilter == Manga.SHOW_READ && !it.read) || + (manga.readFilter == Manga.SHOW_UNREAD && it.read) || + (manga.downloadedFilter == Manga.SHOW_DOWNLOADED && + !downloadManager.isChapterDownloaded(it, manga)) || + (manga.bookmarkedFilter == Manga.SHOW_BOOKMARKED && !it.bookmark)) { + return@filter false + } + true + } else { + true + } + }.sortedBy { when (manga.sorting) { Manga.SORTING_NUMBER -> it.chapter_number else -> it.source_order.toFloat() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index f8fd2e70c9..64206b0f67 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -91,6 +91,11 @@ class SettingsReaderController : SettingsController() { titleRes = R.string.skip_read_chapters defaultValue = false } + switchPreference { + key = Keys.skipFiltered + titleRes = R.string.skip_filtered_chapters + defaultValue = true + } switchPreference { key = Keys.alwaysShowChapterTransition titleRes = R.string.always_show_chapter_transition diff --git a/app/src/main/res/layout/reader_chapters_sheet.xml b/app/src/main/res/layout/reader_chapters_sheet.xml index 9c2e5afbc6..e16c97fb59 100644 --- a/app/src/main/res/layout/reader_chapters_sheet.xml +++ b/app/src/main/res/layout/reader_chapters_sheet.xml @@ -14,9 +14,9 @@ + android:focusable="true"> Burn / Darken Keep screen on Skip chapters marked read + Skip filtered chapters Navigation Volume keys Invert volume keys