feat: 修复web阅读时app未退出阅读界面导致的进度bug;移除EventBus.OPEN_CHAPTER

pull/2427/head
Xwite 2 years ago
parent 0e24e62c70
commit a5a4a8d38f
  1. 8
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  2. 1
      app/src/main/java/io/legado/app/constant/EventBus.kt
  3. 13
      app/src/main/java/io/legado/app/model/ReadBook.kt
  4. 9
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt

@ -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("")
}
}

@ -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"

@ -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,18 +57,10 @@ 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) {
setProgress(it)
lastBookPress = null
}
}
}
fun resetData(book: Book) {
ReadBook.book = book
@ -81,6 +75,7 @@ object ReadBook : CoroutineScope by MainScope() {
callBack?.upPageAnim()
upWebBook(book)
lastBookPress = null
webBookProgress = null
synchronized(this) {
loadingChapters.clear()
}

@ -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()
@ -1273,10 +1278,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()

Loading…
Cancel
Save