From a32751cfed9fb15b5e5905d115d85de283c709e2 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Sun, 25 May 2025 22:06:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/ReadManga.kt | 1 + .../app/ui/book/manga/ReadMangaViewModel.kt | 44 ++++++++++++++++++- .../com/script/rhino/RhinoClassShutter.kt | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/ReadManga.kt b/app/src/main/java/io/legado/app/model/ReadManga.kt index 7aabf8058..6483559aa 100644 --- a/app/src/main/java/io/legado/app/model/ReadManga.kt +++ b/app/src/main/java/io/legado/app/model/ReadManga.kt @@ -49,6 +49,7 @@ object ReadManga : CoroutineScope by MainScope() { var durChapterIndex = 0 //章节位置 var chapterSize = 0//总章节 var durChapterPos = 0 + var chapterChanged = false var prevMangaChapter: MangaChapter? = null var curMangaChapter: MangaChapter? = null var nextMangaChapter: MangaChapter? = null diff --git a/app/src/main/java/io/legado/app/ui/book/manga/ReadMangaViewModel.kt b/app/src/main/java/io/legado/app/ui/book/manga/ReadMangaViewModel.kt index a34cb061d..1035f3290 100644 --- a/app/src/main/java/io/legado/app/ui/book/manga/ReadMangaViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/manga/ReadMangaViewModel.kt @@ -10,11 +10,14 @@ import io.legado.app.constant.EventBus import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter +import io.legado.app.data.entities.BookProgress import io.legado.app.exception.NoStackTraceException +import io.legado.app.help.AppWebDav import io.legado.app.help.book.BookHelp import io.legado.app.help.book.isLocal import io.legado.app.help.book.isLocalModified import io.legado.app.help.book.removeType +import io.legado.app.help.book.simulatedTotalChapterNum import io.legado.app.help.config.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.ReadManga @@ -43,6 +46,7 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application) fun initData(intent: Intent, success: (() -> Unit)? = null) { execute { ReadManga.inBookshelf = intent.getBooleanExtra("inBookshelf", true) + ReadManga.chapterChanged = intent.getBooleanExtra("chapterChanged", false) val bookUrl = intent.getStringExtra("bookUrl") val book = when { bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook @@ -88,6 +92,17 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application) ReadManga.loadOrUpContent() } + if (ReadManga.chapterChanged) { + // 有章节跳转不同步阅读进度 + ReadManga.chapterChanged = false + } else if (!isSameBook) { + if (AppConfig.syncBookProgressPlus) { + ReadManga.syncProgress( + { progress -> ReadManga.mCallback?.sureNewProgress(progress) }) + } else { + syncBookProgress(book) + } + } //自动换源 if (!book.isLocal && ReadManga.bookSource == null) { @@ -130,8 +145,7 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application) WebBook.getBookInfoAwait(source, book, canReName = false) return true } catch (e: Throwable) { - // 加载详情页失败 -// ReadBook.upMsg("详情页出错: ${e.localizedMessage}") + ReadManga.mCallback?.loadFail("详情页出错: ${e.localizedMessage}") return false } } @@ -184,6 +198,32 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application) } } + /** + * 同步进度 + */ + fun syncBookProgress( + book: Book, + alertSync: ((progress: BookProgress) -> Unit)? = null + ) { + if (!AppConfig.syncBookProgress) return + execute { + AppWebDav.getBookProgress(book) + }.onError { + AppLog.put("拉取阅读进度失败《${book.name}》\n${it.localizedMessage}", it) + }.onSuccess { progress -> + progress ?: return@onSuccess + if (progress.durChapterIndex < book.durChapterIndex || + (progress.durChapterIndex == book.durChapterIndex + && progress.durChapterPos < book.durChapterPos) + ) { + alertSync?.invoke(progress) + } else if (progress.durChapterIndex < book.simulatedTotalChapterNum()) { + ReadManga.setProgress(progress) + AppLog.put("自动同步阅读进度成功《${book.name}》 ${progress.durChapterTitle}") + } + } + } + /** * 换源 */ diff --git a/modules/rhino/src/main/java/com/script/rhino/RhinoClassShutter.kt b/modules/rhino/src/main/java/com/script/rhino/RhinoClassShutter.kt index 356fe350f..79840be05 100644 --- a/modules/rhino/src/main/java/com/script/rhino/RhinoClassShutter.kt +++ b/modules/rhino/src/main/java/com/script/rhino/RhinoClassShutter.kt @@ -78,6 +78,7 @@ object RhinoClassShutter : ClassShutter { "android.app.AppGlobals", "android.os.Looper", "android.os.Process", + "android.os.FileUtils", "cn.hutool.core.lang.JarClassLoader", "cn.hutool.core.lang.Singleton",