From ce9fb2f1fe03e47c64f0f667a9f7ef040f46bb2f Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 23 May 2021 11:27:52 -0400 Subject: [PATCH] Update reader chapter list filtering to handle not downloaded/bookmarked (closes #5107) --- .../tachiyomi/ui/reader/ReaderPresenter.kt | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) 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 b2a308e9b0..674f1140ec 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,28 +96,22 @@ class ReaderPresenter( val selectedChapter = dbChapters.find { it.id == chapterId } ?: error("Requested chapter of id $chapterId not found in chapter list") - val chaptersForReader = - 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.CHAPTER_SHOW_READ && !it.read) || + val chaptersForReader = when { + (preferences.skipRead() || preferences.skipFiltered()) -> { + val list = dbChapters.filterNot { + when { + preferences.skipRead() && it.read -> true + preferences.skipFiltered() -> { + (manga.readFilter == Manga.CHAPTER_SHOW_READ && !it.read) || (manga.readFilter == Manga.CHAPTER_SHOW_UNREAD && it.read) || - ( - manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED && - !downloadManager.isChapterDownloaded(it, manga) - ) || - (manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED && !it.bookmark) - ) { - return@filter false - } + (manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED && !downloadManager.isChapterDownloaded(it, manga)) || + (manga.downloadedFilter == Manga.CHAPTER_SHOW_NOT_DOWNLOADED && downloadManager.isChapterDownloaded(it, manga)) || + (manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED && !it.bookmark) || + (manga.bookmarkedFilter == Manga.CHAPTER_SHOW_NOT_BOOKMARKED && it.bookmark) } - - true + else -> false } + } .toMutableList() val find = list.find { it.id == chapterId } @@ -125,9 +119,9 @@ class ReaderPresenter( list.add(selectedChapter) } list - } else { - dbChapters } + else -> dbChapters + } when (manga.sorting) { Manga.CHAPTER_SORTING_SOURCE -> ChapterLoadBySource().get(chaptersForReader)