Merge pull request #2427 from Xwite/master

feat: 修复web阅读时app未退出阅读界面导致的进度bug;
This commit is contained in:
Xwite 2022-10-14 20:03:25 +08:00 committed by GitHub
commit 3068eb2138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 17 deletions

View File

@ -16,6 +16,7 @@ import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.BookCover
import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.*
import kotlinx.coroutines.delay
@ -221,6 +222,13 @@ object BookController {
book.durChapterTime = bookProgress.durChapterTime
appDb.bookDao.update(book)
AppWebDav.uploadBookProgress(bookProgress)
ReadBook.book?.let {
if (it.name == bookProgress.name &&
it.author == bookProgress.author
) {
ReadBook.webBookProgress = bookProgress
}
}
return returnData.setData("")
}
}

View File

@ -12,7 +12,6 @@ object EventBus {
const val BATTERY_CHANGED = "batteryChanged"
const val TIME_CHANGED = "timeChanged"
const val UP_CONFIG = "upConfig"
const val OPEN_CHAPTER = "openChapter"
const val AUDIO_SUB_TITLE = "audioSubTitle"
const val AUDIO_STATE = "audioState"
const val AUDIO_PROGRESS = "audioProgress"

View File

@ -46,6 +46,8 @@ object ReadBook : CoroutineScope by MainScope() {
var bookProgressHistory: List<BookProgress>? = null
/* 跳转进度前进度记录 */
var lastBookPress: BookProgress? = null
/* web端阅读进度记录 */
var webBookProgress: BookProgress? = null
//暂时保存跳转前进度
fun saveCurrentBookProcess() {
@ -55,16 +57,8 @@ object ReadBook : CoroutineScope by MainScope() {
//恢复跳转前进度
fun restoreLastBookProcess() {
lastBookPress?.let {
durChapterPos = it.durChapterPos
if (durChapterIndex != it.durChapterIndex) {
clearTextChapter()
durChapterIndex = it.durChapterIndex
}
callBack?.upContent()
saveRead()
loadContent(resetPageOffset = true) {
lastBookPress = null
}
setProgress(it)
lastBookPress = null
}
}
@ -81,6 +75,7 @@ object ReadBook : CoroutineScope by MainScope() {
callBack?.upPageAnim()
upWebBook(book)
lastBookPress = null
webBookProgress = null
synchronized(this) {
loadingChapters.clear()
}

View File

@ -202,6 +202,11 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun onResume() {
super.onResume()
ReadBook.readStartTime = System.currentTimeMillis()
//web端阅读时app处于阅读界面本地记录会覆盖web保存的进度在此处恢复
ReadBook.webBookProgress?.let {
ReadBook.setProgress(it)
ReadBook.webBookProgress = null
}
upSystemUiVisibility()
registerReceiver(timeBatteryReceiver, timeBatteryReceiver.filter)
binding.readView.upTime()
@ -1170,6 +1175,7 @@ class ReadBookActivity : BaseReadBookActivity(),
/* 进度条跳转到指定章节 */
override fun skipToChapter(index: Int) {
ReadBook.saveCurrentBookProcess() //退出章节跳转恢复此时进度
viewModel.openChapter(index)
}
@ -1271,10 +1277,6 @@ class ReadBookActivity : BaseReadBookActivity(),
super.observeLiveBus()
observeEvent<String>(EventBus.TIME_CHANGED) { readView.upTime() }
observeEvent<Int>(EventBus.BATTERY_CHANGED) { readView.upBattery(it) }
observeEvent<BookChapter>(EventBus.OPEN_CHAPTER) {
viewModel.openChapter(it.index, ReadBook.durChapterPos)
readView.upContent()
}
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) {
onClickReadAloud()

View File

@ -375,13 +375,11 @@ class ReadMenu @JvmOverloads constructor(
"page" -> ReadBook.skipToPage(seekBar.progress)
"chapter" -> {
if (confirmSkipToChapter) {
ReadBook.saveCurrentBookProcess()
callBack.skipToChapter(seekBar.progress)
} else {
context.alert("章节跳转确认", "确定要跳转章节吗?") {
yesButton {
confirmSkipToChapter = true
ReadBook.saveCurrentBookProcess()
callBack.skipToChapter(seekBar.progress)
}
noButton {