Skip filtered chapters while reading

This commit is contained in:
arkon 2020-05-21 14:00:55 -04:00 committed by Jay
parent 62e2a895f5
commit bd748f6a62
6 changed files with 49 additions and 5 deletions

View File

@ -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"

View File

@ -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)

View File

@ -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<ReaderChapterItem> {
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()

View File

@ -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

View File

@ -14,9 +14,9 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/topbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:layout_height="wrap_content">
android:focusable="true">
<ImageView
android:id="@+id/pill"

View File

@ -304,6 +304,7 @@
<string name="burn_darken">Burn / Darken</string>
<string name="keep_screen_on">Keep screen on</string>
<string name="skip_read_chapters">Skip chapters marked read</string>
<string name="skip_filtered_chapters">Skip filtered chapters</string>
<string name="navigation">Navigation</string>
<string name="volume_keys">Volume keys</string>
<string name="invert_volume_keys">Invert volume keys</string>