From 2e0786f699cc6d4863eb20331739c8325a451e63 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sat, 13 Dec 2025 00:49:57 +0600 Subject: [PATCH] Fix reader not saving read duration when changing chapter (#2784) --- CHANGELOG.md | 1 + .../tachiyomi/ui/reader/ReaderActivity.kt | 4 ++- .../tachiyomi/ui/reader/ReaderViewModel.kt | 26 +++++++------------ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ed0fd1d3..be483bede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Fix reader tap zones triggering after scrolling is stopped by tapping ([@NGB-Was-Taken](https://github.com/NGB-Was-Taken)) ([#2680](https://github.com/mihonapp/mihon/pull/2680)) - Fix shizuku installer not updating installed extensions ([@NGB-Was-Taken](https://github.com/NGB-Was-Taken)) ([#2697](https://github.com/mihonapp/mihon/pull/2697)) - Fix mass migration not using the same search queries as individual migration ([@AntsyLich](https://github.com/AntsyLich)) ([#2736](https://github.com/mihonapp/mihon/pull/2736)) +- Fix reader not saving read duration when changing chapter ([@AntsyLich](https://github.com/AntsyLich), [@KotlinHero](https://github.com/KotlinHero)) ([#2784](https://github.com/mihonapp/mihon/pull/2784)) ## [v0.19.3] - 2025-11-07 ### Improved 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 602492f1d..7fac52cab 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 @@ -344,7 +344,9 @@ class ReaderActivity : BaseActivity() { } override fun onPause() { - viewModel.flushReadTimer() + lifecycleScope.launchNonCancellable { + viewModel.updateHistory() + } super.onPause() } 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 31e99742e..77f8048c2 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 @@ -346,7 +346,7 @@ class ReaderViewModel @JvmOverloads constructor( viewModelScope.launchIO { logcat { "Loading ${chapter.chapter.url}" } - flushReadTimer() + updateHistory() restartReadTimer() try { @@ -585,26 +585,20 @@ class ReaderViewModel @JvmOverloads constructor( chapterReadStartTime = Instant.now().toEpochMilli() } - fun flushReadTimer() { - getCurrentChapter()?.let { - viewModelScope.launchNonCancellable { - updateHistory(it) - } - } - } - /** * Saves the chapter last read history if incognito mode isn't on. */ - private suspend fun updateHistory(readerChapter: ReaderChapter) { - if (incognitoMode) return + suspend fun updateHistory() { + getCurrentChapter()?.let { readerChapter -> + if (incognitoMode) return@let - val chapterId = readerChapter.chapter.id!! - val endTime = Date() - val sessionReadDuration = chapterReadStartTime?.let { endTime.time - it } ?: 0 + val chapterId = readerChapter.chapter.id!! + val endTime = Date() + val sessionReadDuration = chapterReadStartTime?.let { endTime.time - it } ?: 0 - upsertHistory.await(HistoryUpdate(chapterId, endTime, sessionReadDuration)) - chapterReadStartTime = null + upsertHistory.await(HistoryUpdate(chapterId, endTime, sessionReadDuration)) + chapterReadStartTime = null + } } /**