From 0e24e62c700f7db179d3e9338e3520e64fb71cc8 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Mon, 10 Oct 2022 15:28:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AB=A0=E8=8A=82?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E8=BF=9B=E5=BA=A6=E6=97=A0=E6=B3=95=E6=81=A2?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 1 + app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) 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 aa53b8c87..b9f8b42a6 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 @@ -1171,6 +1171,7 @@ class ReadBookActivity : BaseReadBookActivity(), /* 进度条跳转到指定章节 */ override fun skipToChapter(index: Int) { + ReadBook.saveCurrentBookProcess() //退出章节跳转恢复此时进度 viewModel.openChapter(index) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 96a51445d..0de1c6fb2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -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 { 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 2/2] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dweb=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E6=97=B6app=E6=9C=AA=E9=80=80=E5=87=BA=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E7=95=8C=E9=9D=A2=E5=AF=BC=E8=87=B4=E7=9A=84=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6bug;=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()