From a3b660a2c95e4d6b86cf39fafee62cee9541d711 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 1 Apr 2020 22:37:28 -0400 Subject: [PATCH] Respect chapter list filtering when reading (closes #2810) --- .../data/preference/PreferenceKeys.kt | 2 + .../data/preference/PreferencesHelper.kt | 2 + .../tachiyomi/ui/reader/ReaderPresenter.kt | 23 ++- .../ui/setting/SettingsReaderController.kt | 186 ++++++++++-------- app/src/main/res/values/strings.xml | 2 + 5 files changed, 128 insertions(+), 87 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 e43c2e9578..d6fbd5c69b 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 @@ -135,6 +135,8 @@ object PreferenceKeys { const val skipRead = "skip_read" + const val skipFiltered = "skip_filtered" + const val downloadBadge = "display_download_badge" const val alwaysShowChapterTransition = "always_show_chapter_transition" 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 cb92b86a39..3445d00f36 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 @@ -208,6 +208,8 @@ class PreferencesHelper(val context: Context) { fun skipRead() = prefs.getBoolean(Keys.skipRead, false) + fun skipFiltered() = prefs.getBoolean(Keys.skipFiltered, false) + fun migrateFlags() = rxPrefs.getInteger("migrate_flags", Int.MAX_VALUE) fun trustedSignatures() = rxPrefs.getStringSet("trusted_signatures", emptySet()) 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 d4dc5646e7..28420cf707 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 @@ -91,8 +91,27 @@ 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) 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 28abac4f0f..1176b010ad 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 @@ -16,97 +16,111 @@ class SettingsReaderController : SettingsController() { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { titleRes = R.string.pref_category_reader - intListPreference { - key = Keys.defaultViewer - titleRes = R.string.pref_viewer_type - entriesRes = arrayOf(R.string.left_to_right_viewer, R.string.right_to_left_viewer, - R.string.vertical_viewer, R.string.webtoon_viewer) - entryValues = arrayOf("1", "2", "3", "4") - defaultValue = "1" - summary = "%s" - } - intListPreference { - key = Keys.imageScaleType - titleRes = R.string.pref_image_scale_type - entriesRes = arrayOf(R.string.scale_type_fit_screen, R.string.scale_type_stretch, - R.string.scale_type_fit_width, R.string.scale_type_fit_height, - R.string.scale_type_original_size, R.string.scale_type_smart_fit) - entryValues = arrayOf("1", "2", "3", "4", "5", "6") - defaultValue = "1" - summary = "%s" - } - intListPreference { - key = Keys.zoomStart - titleRes = R.string.pref_zoom_start - entriesRes = arrayOf(R.string.zoom_start_automatic, R.string.zoom_start_left, - R.string.zoom_start_right, R.string.zoom_start_center) - entryValues = arrayOf("1", "2", "3", "4") - defaultValue = "1" - summary = "%s" - } - intListPreference { - key = Keys.rotation - titleRes = R.string.pref_rotation_type - entriesRes = arrayOf(R.string.rotation_free, R.string.rotation_lock, - R.string.rotation_force_portrait, R.string.rotation_force_landscape) - entryValues = arrayOf("1", "2", "3", "4") - defaultValue = "1" - summary = "%s" - } - intListPreference { - key = Keys.readerTheme - titleRes = R.string.pref_reader_theme - entriesRes = arrayOf(R.string.white_background, R.string.black_background) - entryValues = arrayOf("0", "1") - defaultValue = "0" - summary = "%s" - } - intListPreference { - key = Keys.doubleTapAnimationSpeed - titleRes = R.string.pref_double_tap_anim_speed - entries = arrayOf(context.getString(R.string.double_tap_anim_speed_0), context.getString(R.string.double_tap_anim_speed_fast), context.getString(R.string.double_tap_anim_speed_normal)) - entryValues = arrayOf("1", "250", "500") // using a value of 0 breaks the image viewer, so min is 1 - defaultValue = "500" - summary = "%s" - } - switchPreference { - key = Keys.skipRead - titleRes = R.string.pref_skip_read_chapters - defaultValue = false - } - switchPreference { - key = Keys.fullscreen - titleRes = R.string.pref_fullscreen - defaultValue = true - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + preferenceCategory { + titleRes = R.string.pref_category_general + + intListPreference { + key = Keys.defaultViewer + titleRes = R.string.pref_viewer_type + entriesRes = arrayOf(R.string.left_to_right_viewer, R.string.right_to_left_viewer, + R.string.vertical_viewer, R.string.webtoon_viewer) + entryValues = arrayOf("1", "2", "3", "4") + defaultValue = "1" + summary = "%s" + } + intListPreference { + key = Keys.imageScaleType + titleRes = R.string.pref_image_scale_type + entriesRes = arrayOf(R.string.scale_type_fit_screen, R.string.scale_type_stretch, + R.string.scale_type_fit_width, R.string.scale_type_fit_height, + R.string.scale_type_original_size, R.string.scale_type_smart_fit) + entryValues = arrayOf("1", "2", "3", "4", "5", "6") + defaultValue = "1" + summary = "%s" + } + intListPreference { + key = Keys.zoomStart + titleRes = R.string.pref_zoom_start + entriesRes = arrayOf(R.string.zoom_start_automatic, R.string.zoom_start_left, + R.string.zoom_start_right, R.string.zoom_start_center) + entryValues = arrayOf("1", "2", "3", "4") + defaultValue = "1" + summary = "%s" + } + intListPreference { + key = Keys.rotation + titleRes = R.string.pref_rotation_type + entriesRes = arrayOf(R.string.rotation_free, R.string.rotation_lock, + R.string.rotation_force_portrait, R.string.rotation_force_landscape) + entryValues = arrayOf("1", "2", "3", "4") + defaultValue = "1" + summary = "%s" + } + intListPreference { + key = Keys.readerTheme + titleRes = R.string.pref_reader_theme + entriesRes = arrayOf(R.string.white_background, R.string.black_background) + entryValues = arrayOf("0", "1") + defaultValue = "0" + summary = "%s" + } + intListPreference { + key = Keys.doubleTapAnimationSpeed + titleRes = R.string.pref_double_tap_anim_speed + entries = arrayOf(context.getString(R.string.double_tap_anim_speed_0), context.getString(R.string.double_tap_anim_speed_fast), context.getString(R.string.double_tap_anim_speed_normal)) + entryValues = arrayOf("1", "250", "500") // using a value of 0 breaks the image viewer, so min is 1 + defaultValue = "500" + summary = "%s" + } switchPreference { - key = Keys.cutoutShort - titleRes = R.string.pref_cutout_short + key = Keys.fullscreen + titleRes = R.string.pref_fullscreen defaultValue = true } - } - switchPreference { - key = Keys.keepScreenOn - titleRes = R.string.pref_keep_screen_on - defaultValue = true - } - switchPreference { - key = Keys.showPageNumber - titleRes = R.string.pref_show_page_number - defaultValue = true - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + switchPreference { + key = Keys.cutoutShort + titleRes = R.string.pref_cutout_short + defaultValue = true + } + } switchPreference { - key = Keys.trueColor - titleRes = R.string.pref_true_color - defaultValue = false + key = Keys.keepScreenOn + titleRes = R.string.pref_keep_screen_on + defaultValue = true + } + switchPreference { + key = Keys.showPageNumber + titleRes = R.string.pref_show_page_number + defaultValue = true + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + switchPreference { + key = Keys.trueColor + titleRes = R.string.pref_true_color + defaultValue = false + } } } - switchPreference { - key = Keys.alwaysShowChapterTransition - titleRes = R.string.pref_always_show_chapter_transition - defaultValue = true + + preferenceCategory { + titleRes = R.string.pref_category_reading + + switchPreference { + key = Keys.skipRead + titleRes = R.string.pref_skip_read_chapters + defaultValue = false + } + switchPreference { + key = Keys.skipFiltered + titleRes = R.string.pref_skip_filtered_chapters + defaultValue = false + } + switchPreference { + key = Keys.alwaysShowChapterTransition + titleRes = R.string.pref_always_show_chapter_transition + defaultValue = true + } } preferenceCategory { @@ -123,6 +137,7 @@ class SettingsReaderController : SettingsController() { defaultValue = false } } + preferenceCategory { titleRes = R.string.webtoon_viewer @@ -137,6 +152,7 @@ class SettingsReaderController : SettingsController() { defaultValue = false } } + preferenceCategory { titleRes = R.string.pref_reader_navigation diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e1c5550271..64dd3d5fc8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -234,6 +234,7 @@ Burn / Darken Keep screen on Skip chapters marked read + Skip filtered chapters Navigation Volume keys Invert volume keys @@ -275,6 +276,7 @@ B A Always show chapter transition + Reading Download location