From 4dd67e4348b5eaf627b6594f911071f6821a46f1 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 5 Apr 2023 22:29:56 -0400 Subject: [PATCH] Save current chapter progress when navigating to adjacent chapters Fixes #9295 (cherry picked from commit 776d36caf11cf29287e4cb86a6e64574a296f89c) --- .../tachiyomi/ui/reader/ReaderActivity.kt | 8 ++---- .../tachiyomi/ui/reader/ReaderViewModel.kt | 25 ++++++++++--------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 0d1d2ef09..dec65e761 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -99,10 +99,6 @@ import uy.kohesive.injekt.injectLazy import kotlin.math.abs import kotlin.math.max -/** - * Activity containing the reader of Tachiyomi. This activity is mostly a container of the - * viewers, to which calls from the presenter or UI events are delegated. - */ class ReaderActivity : BaseActivity() { companion object { @@ -661,7 +657,7 @@ class ReaderActivity : BaseActivity() { * Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer * and the toolbar title. */ - fun setManga(manga: Manga) { + private fun setManga(manga: Manga) { val prevViewer = viewer val viewerMode = ReadingModeType.fromPreference(viewModel.getMangaReadingMode(resolveDefault = false)) @@ -776,7 +772,7 @@ class ReaderActivity : BaseActivity() { * Called from the presenter if the initial load couldn't load the pages of the chapter. In * this case the activity is closed and a toast is shown to the user. */ - fun setInitialChapterError(error: Throwable) { + private fun setInitialChapterError(error: Throwable) { logcat(LogPriority.ERROR, error) finish() toast(error.message) 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 203bcbff1..fae7f638d 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 @@ -201,17 +201,6 @@ class ReaderViewModel( private val incognitoMode = preferences.incognitoMode().get() - override fun onCleared() { - val currentChapters = state.value.viewerChapters - if (currentChapters != null) { - currentChapters.unref() - saveReadingProgress(currentChapters.currChapter) - chapterToDownload?.let { - downloadManager.addDownloadsToStartOfQueue(listOf(it)) - } - } - } - init { // To save state state.map { it.viewerChapters?.currChapter } @@ -226,6 +215,17 @@ class ReaderViewModel( .launchIn(viewModelScope) } + override fun onCleared() { + val currentChapters = state.value.viewerChapters + if (currentChapters != null) { + currentChapters.unref() + saveReadingProgress(currentChapters.currChapter) + chapterToDownload?.let { + downloadManager.addDownloadsToStartOfQueue(listOf(it)) + } + } + } + /** * Called when the user pressed the back button and is going to leave the reader. Used to * trigger deletion of the downloaded chapters. @@ -338,10 +338,11 @@ class ReaderViewModel( } /** - * Called when the user is going to load the prev/next chapter through the menu button. + * Called when the user is going to load the prev/next chapter through the toolbar buttons. */ private suspend fun loadAdjacent(chapter: ReaderChapter) { val loader = loader ?: return + saveCurrentChapterReadingProgress() logcat { "Loading adjacent ${chapter.chapter.url}" }