From f94ce733b2f681816543e29ca316dfe5a5af2967 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 10 Jan 2022 20:54:13 +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 --- .../main/java/io/legado/app/model/ReadBook.kt | 15 +++++++------- .../app/ui/book/read/ReadBookViewModel.kt | 20 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) 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 99eb3d7ff..1b64f214c 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -90,15 +90,14 @@ object ReadBook : CoroutineScope by MainScope() { } fun setProgress(progress: BookProgress) { - if (durChapterIndex != progress.durChapterIndex - || durChapterPos != progress.durChapterPos + if (progress.durChapterIndex > chapterSize && + (durChapterIndex != progress.durChapterIndex + || durChapterPos != progress.durChapterPos) ) { - if (progress.durChapterIndex > chapterSize) { - durChapterIndex = progress.durChapterIndex - durChapterPos = progress.durChapterPos - clearTextChapter() - loadContent(resetPageOffset = true) - } + durChapterIndex = progress.durChapterIndex + durChapterPos = progress.durChapterPos + clearTextChapter() + loadContent(resetPageOffset = true) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index af2b146fe..de573fed9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -220,15 +220,17 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) { - ReadBook.clearTextChapter() - ReadBook.callBack?.upContent() - if (index != ReadBook.durChapterIndex) { - ReadBook.durChapterIndex = index - ReadBook.durChapterPos = durChapterPos - } - ReadBook.saveRead() - ReadBook.loadContent(resetPageOffset = true) { - success?.invoke() + if (index < ReadBook.chapterSize) { + ReadBook.clearTextChapter() + ReadBook.callBack?.upContent() + if (index != ReadBook.durChapterIndex) { + ReadBook.durChapterIndex = index + ReadBook.durChapterPos = durChapterPos + } + ReadBook.saveRead() + ReadBook.loadContent(resetPageOffset = true) { + success?.invoke() + } } }