diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index f1662d6066..652cf6e214 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -12,7 +12,6 @@ import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.source.SourceManager -import eu.kanade.tachiyomi.ui.reader.ReaderChapterFilter import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import uy.kohesive.injekt.api.InjektModule @@ -49,8 +48,6 @@ class AppModule(val app: Application) : InjektModule { addSingletonFactory { Gson() } - addSingletonFactory { ReaderChapterFilter() } - // Asynchronously init expensive components for a faster cold start GlobalScope.launch { get() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterFilter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterFilter.kt index 5f9b127c15..86317a12cb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterFilter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterFilter.kt @@ -4,25 +4,22 @@ import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get /** * This class filters chapters for the reader based on the user enabled preferences and filters */ class ReaderChapterFilter( - private val downloadManager: DownloadManager = Injekt.get(), - private val preferences: PreferencesHelper = Injekt.get() + private val downloadManager: DownloadManager, + private val preferences: PreferencesHelper ) { fun filterChapter( dbChapters: List, manga: Manga, - chapterId: Long, - selectedChapter: Chapter? + selectedChapter: Chapter? = null ): List { - // if neither preference is enabled dont even filter + // if neither preference is enabled don't even filter if (!preferences.skipRead() && !preferences.skipFiltered()) { return dbChapters } @@ -30,15 +27,6 @@ class ReaderChapterFilter( var filteredChapters = dbChapters if (preferences.skipRead()) { filteredChapters = filteredChapters.filter { !it.read } - // add the selected chapter to the list in case it was read and user clicked it - if (chapterId != -1L) { - val find = filteredChapters.find { it.id == chapterId } - if (find == null) { - val mutableList = filteredChapters.toMutableList() - selectedChapter?.let { mutableList.add(it) } - filteredChapters = mutableList.toList() - } - } } if (preferences.skipFiltered()) { val readEnabled = manga.readFilter == Manga.SHOW_READ @@ -61,6 +49,16 @@ class ReaderChapterFilter( } } } + + // add the selected chapter to the list in case it was filtered out + if (selectedChapter?.id != null) { + val find = filteredChapters.find { it.id == selectedChapter.id } + if (find == null) { + val mutableList = filteredChapters.toMutableList() + mutableList.add(selectedChapter) + filteredChapters = mutableList.toList() + } + } return filteredChapters } } 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 712301aabf..e4fddea339 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 @@ -51,10 +51,11 @@ class ReaderPresenter( private val sourceManager: SourceManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(), private val coverCache: CoverCache = Injekt.get(), - private val preferences: PreferencesHelper = Injekt.get(), - private val readerChapterFilter: ReaderChapterFilter = Injekt.get() + private val preferences: PreferencesHelper = Injekt.get() ) : BasePresenter() { + private val readerChapterFilter = ReaderChapterFilter(downloadManager, preferences) + /** * The manga loaded in the reader. It can be null when instantiated for a short time. */ @@ -97,8 +98,8 @@ class ReaderPresenter( val selectedChapter = dbChapters.find { it.id == chapterId } ?: error("Requested chapter of id $chapterId not found in chapter list") - val chaptersForReader = readerChapterFilter - .filterChapter(dbChapters, manga, chapterId, selectedChapter) + val chaptersForReader = + readerChapterFilter.filterChapter(dbChapters, manga, selectedChapter) when (manga.sorting) { Manga.SORTING_SOURCE -> ChapterLoadBySource().get(chaptersForReader) @@ -183,8 +184,8 @@ class ReaderPresenter( val manga = manga ?: return emptyList() chapterItems = withContext(Dispatchers.IO) { val dbChapters = db.getChapters(manga).executeAsBlocking() - val list = readerChapterFilter - .filterChapter(dbChapters, manga, -1L, null) + val list = + readerChapterFilter.filterChapter(dbChapters, manga, getCurrentChapter()?.chapter) .sortedBy { when (manga.sorting) { Manga.SORTING_NUMBER -> it.chapter_number