From a5a4a8d38ffa5d9daf4a4cac73020134d2b53942 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 14 Oct 2022 19:25:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dweb=E9=98=85=E8=AF=BB?= =?UTF-8?q?=E6=97=B6app=E6=9C=AA=E9=80=80=E5=87=BA=E9=98=85=E8=AF=BB?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=AF=BC=E8=87=B4=E7=9A=84=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?bug;=E7=A7=BB=E9=99=A4EventBus.OPEN=5FCHAPTER?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/api/controller/BookController.kt | 8 ++++++++ .../main/java/io/legado/app/constant/EventBus.kt | 1 - app/src/main/java/io/legado/app/model/ReadBook.kt | 15 +++++---------- .../legado/app/ui/book/read/ReadBookActivity.kt | 9 +++++---- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index c7650fd5e..60cb7c9c5 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.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("") } } diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 0f93c36c0..1c8afc674 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -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" diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index a2508eeea..6fed0d013 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -46,6 +46,8 @@ object ReadBook : CoroutineScope by MainScope() { var bookProgressHistory: List? = 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() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index b9f8b42a6..236f6f343 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -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(EventBus.TIME_CHANGED) { readView.upTime() } observeEvent(EventBus.BATTERY_CHANGED) { readView.upBattery(it) } - observeEvent(EventBus.OPEN_CHAPTER) { - viewModel.openChapter(it.index, ReadBook.durChapterPos) - readView.upContent() - } observeEvent(EventBus.MEDIA_BUTTON) { if (it) { onClickReadAloud()