Fix reader not saving read duration when changing chapter (#2784)
This commit is contained in:
@@ -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 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 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 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
|
## [v0.19.3] - 2025-11-07
|
||||||
### Improved
|
### Improved
|
||||||
|
|||||||
@@ -344,7 +344,9 @@ class ReaderActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
viewModel.flushReadTimer()
|
lifecycleScope.launchNonCancellable {
|
||||||
|
viewModel.updateHistory()
|
||||||
|
}
|
||||||
super.onPause()
|
super.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
|||||||
viewModelScope.launchIO {
|
viewModelScope.launchIO {
|
||||||
logcat { "Loading ${chapter.chapter.url}" }
|
logcat { "Loading ${chapter.chapter.url}" }
|
||||||
|
|
||||||
flushReadTimer()
|
updateHistory()
|
||||||
restartReadTimer()
|
restartReadTimer()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -585,26 +585,20 @@ class ReaderViewModel @JvmOverloads constructor(
|
|||||||
chapterReadStartTime = Instant.now().toEpochMilli()
|
chapterReadStartTime = Instant.now().toEpochMilli()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun flushReadTimer() {
|
|
||||||
getCurrentChapter()?.let {
|
|
||||||
viewModelScope.launchNonCancellable {
|
|
||||||
updateHistory(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the chapter last read history if incognito mode isn't on.
|
* Saves the chapter last read history if incognito mode isn't on.
|
||||||
*/
|
*/
|
||||||
private suspend fun updateHistory(readerChapter: ReaderChapter) {
|
suspend fun updateHistory() {
|
||||||
if (incognitoMode) return
|
getCurrentChapter()?.let { readerChapter ->
|
||||||
|
if (incognitoMode) return@let
|
||||||
|
|
||||||
val chapterId = readerChapter.chapter.id!!
|
val chapterId = readerChapter.chapter.id!!
|
||||||
val endTime = Date()
|
val endTime = Date()
|
||||||
val sessionReadDuration = chapterReadStartTime?.let { endTime.time - it } ?: 0
|
val sessionReadDuration = chapterReadStartTime?.let { endTime.time - it } ?: 0
|
||||||
|
|
||||||
upsertHistory.await(HistoryUpdate(chapterId, endTime, sessionReadDuration))
|
upsertHistory.await(HistoryUpdate(chapterId, endTime, sessionReadDuration))
|
||||||
chapterReadStartTime = null
|
chapterReadStartTime = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user