Merge pull request #2427 from Xwite/master

feat: 修复web阅读时app未退出阅读界面导致的进度bug;
pull/2431/head
Xwite 2 years ago committed by GitHub
commit 3068eb2138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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. 15
      app/src/main/java/io/legado/app/model/ReadBook.kt
  4. 10
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.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,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()
}

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

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

Loading…
Cancel
Save