This commit is contained in:
Horis
2024-01-21 09:10:02 +08:00
parent b962e4d049
commit f1721adf3c
2 changed files with 28 additions and 15 deletions
@@ -155,13 +155,14 @@ object ReadBook : CoroutineScope by MainScope() {
}
fun upReadTime() {
if (!AppConfig.enableReadRecord) {
return
}
Coroutine.async(executeContext = IO) {
readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime
readStartTime = System.currentTimeMillis()
readRecord.lastRead = System.currentTimeMillis()
if (AppConfig.enableReadRecord) {
appDb.readRecordDao.insert(readRecord)
}
appDb.readRecordDao.insert(readRecord)
}
}
@@ -180,7 +181,7 @@ object ReadBook : CoroutineScope by MainScope() {
hasNextPage = true
durChapterPos = nextPagePos
callBack?.upContent()
saveRead()
saveRead(true)
}
}
return hasNextPage
@@ -194,7 +195,7 @@ object ReadBook : CoroutineScope by MainScope() {
hasPrevPage = true
durChapterPos = prevPagePos
callBack?.upContent()
saveRead()
saveRead(true)
}
}
return hasPrevPage
@@ -259,12 +260,12 @@ object ReadBook : CoroutineScope by MainScope() {
success?.invoke()
}
curPageChanged()
saveRead()
saveRead(true)
}
fun setPageIndex(index: Int) {
durChapterPos = curTextChapter?.getReadLength(index) ?: index
saveRead()
saveRead(true)
curPageChanged(true)
}
@@ -519,7 +520,7 @@ object ReadBook : CoroutineScope by MainScope() {
saveRead()
}
fun saveRead() {
fun saveRead(pageChanged: Boolean = false) {
Coroutine.async(executeContext = IO) {
val book = book ?: return@async
book.lastCheckCount = 0
@@ -527,7 +528,7 @@ object ReadBook : CoroutineScope by MainScope() {
val chapterChanged = book.durChapterIndex != durChapterIndex
book.durChapterIndex = durChapterIndex
book.durChapterPos = durChapterPos
if (chapterChanged) {
if (!pageChanged || chapterChanged) {
appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
book.durChapterTitle = it.getDisplayTitle(
ContentProcessor.get(book.name, book.origin).getTitleReplaceRules(),
@@ -21,7 +21,11 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ActivityBookInfoBinding
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.AppWebDav
import io.legado.app.help.book.*
import io.legado.app.help.book.getRemoteUrl
import io.legado.app.help.book.isAudio
import io.legado.app.help.book.isLocal
import io.legado.app.help.book.isLocalTxt
import io.legado.app.help.book.isWebFile
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.LocalConfig
import io.legado.app.lib.dialogs.alert
@@ -47,8 +51,20 @@ import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.widget.dialog.PhotoDialog
import io.legado.app.ui.widget.dialog.VariableDialog
import io.legado.app.ui.widget.dialog.WaitDialog
import io.legado.app.utils.*
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.GSON
import io.legado.app.utils.StartActivityContract
import io.legado.app.utils.dpToPx
import io.legado.app.utils.gone
import io.legado.app.utils.longToastOnUi
import io.legado.app.utils.openFileUri
import io.legado.app.utils.sendToClip
import io.legado.app.utils.shareWithQr
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -70,10 +86,6 @@ class BookInfoActivity :
chapterChanged = it.third
appDb.bookDao.update(book)
}
viewModel.chapterListData.value?.let { chapterList ->
binding.tvToc.text =
getString(R.string.toc_s, chapterList[book.durChapterIndex].title)
}
startReadActivity(book)
}
}