From dddba7bb6f1fdea7c853d07a3c8f0ad7c99a12d5 Mon Sep 17 00:00:00 2001 From: Simon <71730726+HerrGeist@users.noreply.github.com> Date: Sat, 10 Jun 2023 16:48:15 +0000 Subject: [PATCH] Filter out non-downloaded chapters in reader when Downloaded Only is enabled (#9568) * FIxed Issue #5463 - DownloadedOnly Bug * Changes according to Feedback * Changes according to Feedback --------- Co-authored-by: AlphiGhost <71730726+AlphiGhost@users.noreply.github.com> --- .../tachiyomi/ui/reader/ReaderViewModel.kt | 9 +++++++++ .../util/chapter/ChapterFilterDownloaded.kt | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterFilterDownloaded.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index 0af41b5922..ebf1500087 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -34,6 +34,7 @@ import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType import eu.kanade.tachiyomi.ui.reader.viewer.Viewer +import eu.kanade.tachiyomi.util.chapter.filterDownloaded import eu.kanade.tachiyomi.util.chapter.removeDuplicates import eu.kanade.tachiyomi.util.editCover import eu.kanade.tachiyomi.util.lang.byteSize @@ -91,6 +92,7 @@ class ReaderViewModel( private val downloadProvider: DownloadProvider = Injekt.get(), private val imageSaver: ImageSaver = Injekt.get(), preferences: BasePreferences = Injekt.get(), + private val basePreferences: BasePreferences = Injekt.get(), private val downloadPreferences: DownloadPreferences = Injekt.get(), private val readerPreferences: ReaderPreferences = Injekt.get(), private val trackPreferences: TrackPreferences = Injekt.get(), @@ -184,6 +186,13 @@ class ReaderViewModel( this } } + .run { + if (basePreferences.downloadedOnly().get()) { + filterDownloaded(manga) + } else { + this + } + } .map { it.toDbChapter() } .map(::ReaderChapter) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterFilterDownloaded.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterFilterDownloaded.kt new file mode 100644 index 0000000000..e8731d838d --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterFilterDownloaded.kt @@ -0,0 +1,16 @@ +package eu.kanade.tachiyomi.util.chapter + +import eu.kanade.tachiyomi.data.download.DownloadCache +import tachiyomi.domain.chapter.model.Chapter +import tachiyomi.domain.manga.model.Manga +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get + +/** + * Returns a copy of the list with not downloaded chapters removed + */ +fun List.filterDownloaded(manga: Manga): List { + val downloadCache: DownloadCache = Injekt.get() + + return filter { downloadCache.isChapterDownloaded(it.name, it.scanlator, manga.title, manga.source, false) } +}