Fix reader not saving read duration when changing chapter (mihonapp/mihon#2784)
(cherry picked from commit 2e0786f699cc6d4863eb20331739c8325a451e63)
This commit is contained in:
parent
a5d8f2efac
commit
2274e901a1
2 changed files with 13 additions and 17 deletions
|
|
@ -323,7 +323,9 @@ class ReaderActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
viewModel.flushReadTimer()
|
lifecycleScope.launchNonCancellable {
|
||||||
|
viewModel.updateHistory()
|
||||||
|
}
|
||||||
|
|
||||||
// AM (DISCORD) -->
|
// AM (DISCORD) -->
|
||||||
updateDiscordRPC(exitingReader = true)
|
updateDiscordRPC(exitingReader = true)
|
||||||
|
|
|
||||||
|
|
@ -571,7 +571,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 {
|
||||||
|
|
@ -879,26 +879,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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue