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. 13
      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.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()
@ -1170,6 +1175,7 @@ class ReadBookActivity : BaseReadBookActivity(),
/* 进度条跳转到指定章节 */ /* 进度条跳转到指定章节 */
override fun skipToChapter(index: Int) { override fun skipToChapter(index: Int) {
ReadBook.saveCurrentBookProcess() //退出章节跳转恢复此时进度
viewModel.openChapter(index) viewModel.openChapter(index)
} }
@ -1271,10 +1277,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()

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

Loading…
Cancel
Save