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

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

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

@ -202,6 +202,11 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
ReadBook.readStartTime = System.currentTimeMillis() ReadBook.readStartTime = System.currentTimeMillis()
//web端阅读时,app处于阅读界面,本地记录会覆盖web保存的进度,在此处恢复
ReadBook.webBookProgress?.let {
ReadBook.setProgress(it)
ReadBook.webBookProgress = null
}
upSystemUiVisibility() upSystemUiVisibility()
registerReceiver(timeBatteryReceiver, timeBatteryReceiver.filter) registerReceiver(timeBatteryReceiver, timeBatteryReceiver.filter)
binding.readView.upTime() binding.readView.upTime()
@ -1273,10 +1278,6 @@ class ReadBookActivity : BaseReadBookActivity(),
super.observeLiveBus() super.observeLiveBus()
observeEvent<String>(EventBus.TIME_CHANGED) { readView.upTime() } observeEvent<String>(EventBus.TIME_CHANGED) { readView.upTime() }
observeEvent<Int>(EventBus.BATTERY_CHANGED) { readView.upBattery(it) } 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) { observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) { if (it) {
onClickReadAloud() onClickReadAloud()

Loading…
Cancel
Save