From ea47a2473776ba6df5b484aafd2fc2c753fa3821 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Thu, 22 Feb 2024 12:35:48 +0800 Subject: [PATCH 1/5] =?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 | 48 ++++++++++++++++--- .../app/ui/book/read/ReadBookActivity.kt | 37 +++++++++++++- .../legado/app/ui/book/read/page/ReadView.kt | 27 +---------- .../ui/book/read/page/entities/TextChapter.kt | 6 ++- .../page/provider/LayoutProgressListener.kt | 6 +-- .../read/page/provider/TextChapterLayout.kt | 10 ++-- 6 files changed, 92 insertions(+), 42 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 01c222b75..296dca9fe 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -19,7 +19,9 @@ import io.legado.app.model.localBook.TextFile import io.legado.app.model.webBook.WebBook import io.legado.app.service.BaseReadAloudService import io.legado.app.ui.book.read.page.entities.TextChapter +import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.provider.ChapterProvider +import io.legado.app.ui.book.read.page.provider.LayoutProgressListener import io.legado.app.utils.stackTraceStr import io.legado.app.utils.toastOnUi import kotlinx.coroutines.CoroutineScope @@ -214,6 +216,7 @@ object ReadBook : CoroutineScope by MainScope() { durChapterPos = 0 durChapterIndex++ prevTextChapter?.cancelLayout() + curTextChapter?.setProgressListener(null) prevTextChapter = curTextChapter curTextChapter = nextTextChapter nextTextChapter = null @@ -230,7 +233,7 @@ object ReadBook : CoroutineScope by MainScope() { callBack?.upMenuView() AppLog.putDebug("moveToNextChapter-curPageChanged()") curPageChanged() - curTextChapter?.let { callBack?.onCurrentTextChapterChanged(it) } + curTextChapter?.let { callBack?.onCurrentTextChapterChanged(it, upContent) } return true } else { AppLog.putDebug("跳转下一章失败,没有下一章") @@ -247,6 +250,7 @@ object ReadBook : CoroutineScope by MainScope() { durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: Int.MAX_VALUE else 0 durChapterIndex-- nextTextChapter?.cancelLayout() + curTextChapter?.setProgressListener(null) nextTextChapter = curTextChapter curTextChapter = prevTextChapter prevTextChapter = null @@ -260,7 +264,7 @@ object ReadBook : CoroutineScope by MainScope() { saveRead() callBack?.upMenuView() curPageChanged() - curTextChapter?.let { callBack?.onCurrentTextChapterChanged(it) } + curTextChapter?.let { callBack?.onCurrentTextChapterChanged(it, upContent) } return true } else { return false @@ -495,24 +499,52 @@ object ReadBook : CoroutineScope by MainScope() { when (val offset = chapter.index - durChapterIndex) { 0 -> { curTextChapter?.cancelLayout() + curTextChapter?.setProgressListener(null) curTextChapter = textChapter - if (upContent) callBack?.upContent(offset, resetPageOffset) + if (textChapter.isCompleted) { + if (upContent) callBack?.upContent(offset, resetPageOffset) + } else if (resetPageOffset) { + callBack?.resetPageOffset() + } callBack?.upMenuView() curPageChanged() callBack?.contentLoadFinish() - callBack?.onCurrentTextChapterChanged(textChapter) + callBack?.onCurrentTextChapterChanged(textChapter, upContent) } -1 -> { prevTextChapter?.cancelLayout() prevTextChapter = textChapter - if (upContent) callBack?.upContent(offset, resetPageOffset) + if (upContent) { + if (textChapter.isCompleted) { + callBack?.upContent(offset, resetPageOffset) + } else { + textChapter.setProgressListener(object : LayoutProgressListener { + override fun onLayoutCompleted() { + callBack?.upContent(offset, resetPageOffset) + } + }) + } + } } 1 -> { nextTextChapter?.cancelLayout() nextTextChapter = textChapter - if (upContent) callBack?.upContent(offset, resetPageOffset) + if (upContent) { + if (textChapter.isCompleted) { + callBack?.upContent(offset, resetPageOffset) + } else { + textChapter.setProgressListener(object : LayoutProgressListener { + override fun onLayoutPageCompleted(index: Int, page: TextPage) { + if (index > 1) { + return + } + callBack?.upContent(offset, resetPageOffset) + } + }) + } + } } } Unit @@ -650,7 +682,9 @@ object ReadBook : CoroutineScope by MainScope() { fun notifyBookChanged() - fun onCurrentTextChapterChanged(textChapter: TextChapter) + fun onCurrentTextChapterChanged(textChapter: TextChapter, upContent: Boolean = true) + + fun resetPageOffset() } } 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 a0bcf2649..33bad1ffa 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 @@ -126,6 +126,7 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlin.math.max /** * 阅读界面 @@ -233,6 +234,7 @@ class ReadBookActivity : BaseReadBookActivity(), binding.readMenu.upSeekBar() } } + private var upContent = true //恢复跳转前进度对话框的交互结果 private var confirmRestoreProcess: Boolean? = null @@ -936,7 +938,9 @@ class ReadBookActivity : BaseReadBookActivity(), ) { lifecycleScope.launch { binding.readView.upContent(relativePosition, resetPageOffset) - upSeekBarProgress() + if (relativePosition == 0) { + upSeekBarProgress() + } loadStates = false success?.invoke() } @@ -1369,16 +1373,41 @@ class ReadBookActivity : BaseReadBookActivity(), binding.readView.autoPager.resume() } - override fun onCurrentTextChapterChanged(textChapter: TextChapter) { + override fun onCurrentTextChapterChanged(textChapter: TextChapter, upContent: Boolean) { + this.upContent = upContent textChapter.setProgressListener(this) } override fun onLayoutPageCompleted(index: Int, page: TextPage) { upSeekBarThrottle.invoke() + if (upContent) { + val line = page.lines.first() + val durChapterPos = ReadBook.durChapterPos + val startPos = line.chapterPosition + val endPos = startPos + line.charSize + if (durChapterPos in startPos.. y } for (lineIndex in 0 until layout.lineCount) { - coroutineContext.ensureActive() val textLine = TextLine(isTitle = isTitle) if (durY + textHeight > visibleHeight) { val textPage = textPages.last() @@ -438,6 +441,7 @@ class TextChapterLayout( textPage.leftLineSize = textPage.lineSize } textPage.text = stringBuilder.toString() + coroutineContext.ensureActive() onPageCompleted() //新建页面 textPages.add(TextPage()) From fc6a35ff6dbe61dfa553a3fb14049b743879c72a Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Thu, 22 Feb 2024 13:05:38 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/provider/TextChapterLayout.kt | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt index 3a2f4f486..3ab22cad6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt @@ -13,6 +13,7 @@ import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.coroutine.Coroutine +import io.legado.app.help.globalExecutor import io.legado.app.model.ImageProvider import io.legado.app.model.ReadBook import io.legado.app.ui.book.read.page.entities.TextChapter @@ -68,7 +69,7 @@ class TextChapterLayout( private val stringBuilder = StringBuilder() private var isCompleted = false - private val job: Coroutine<*> + private var job: Coroutine<*>? = null private val bookChapter inline get() = textChapter.chapter private val displayTitle inline get() = textChapter.title private val chaptersSize inline get() = textChapter.chaptersSize @@ -76,17 +77,19 @@ class TextChapterLayout( var exception: Throwable? = null init { - job = Coroutine.async(scope) { - launch { - val bookSource = book.getBookSource() ?: return@launch - BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString()) + globalExecutor.submit { + job = Coroutine.async(scope) { + launch { + val bookSource = book.getBookSource() ?: return@launch + BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString()) + } + getTextChapter(book, bookChapter, displayTitle, bookContent) + }.onError { + exception = it + onException(it) + }.onFinally { + isCompleted = true } - getTextChapter(book, bookChapter, displayTitle, bookContent) - }.onError { - exception = it - onException(it) - }.onFinally { - isCompleted = true } } @@ -106,7 +109,7 @@ class TextChapterLayout( } fun cancel() { - job.cancel() + job?.cancel() } private fun onPageCompleted() { From 3449fd7c868e96d123ca736e8dc50fddc99be729 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Thu, 22 Feb 2024 15:36:13 +0800 Subject: [PATCH 3/5] =?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 | 48 +++++++------------ .../legado/app/ui/book/read/page/PageView.kt | 4 ++ .../legado/app/ui/book/read/page/ReadView.kt | 6 ++- .../read/page/provider/ChapterProvider.kt | 7 +-- .../read/page/provider/TextChapterLayout.kt | 27 +++++------ 5 files changed, 38 insertions(+), 54 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 296dca9fe..e5af2b870 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -488,22 +488,14 @@ object ReadBook : CoroutineScope by MainScope() { ) val contents = contentProcessor .getContent(book, chapter, content, includeTitle = false) - val textChapter = ChapterProvider.getTextChapterAsync( - book, - chapter, - displayTitle, - contents, - chapterSize, - this@ReadBook - ) + val textChapter = + ChapterProvider.getTextChapterAsync(chapter, displayTitle, contents, chapterSize) when (val offset = chapter.index - durChapterIndex) { 0 -> { curTextChapter?.cancelLayout() curTextChapter?.setProgressListener(null) curTextChapter = textChapter - if (textChapter.isCompleted) { - if (upContent) callBack?.upContent(offset, resetPageOffset) - } else if (resetPageOffset) { + if (resetPageOffset) { callBack?.resetPageOffset() } callBack?.upMenuView() @@ -516,15 +508,11 @@ object ReadBook : CoroutineScope by MainScope() { prevTextChapter?.cancelLayout() prevTextChapter = textChapter if (upContent) { - if (textChapter.isCompleted) { - callBack?.upContent(offset, resetPageOffset) - } else { - textChapter.setProgressListener(object : LayoutProgressListener { - override fun onLayoutCompleted() { - callBack?.upContent(offset, resetPageOffset) - } - }) - } + textChapter.setProgressListener(object : LayoutProgressListener { + override fun onLayoutCompleted() { + callBack?.upContent(offset, resetPageOffset) + } + }) } } @@ -532,22 +520,18 @@ object ReadBook : CoroutineScope by MainScope() { nextTextChapter?.cancelLayout() nextTextChapter = textChapter if (upContent) { - if (textChapter.isCompleted) { - callBack?.upContent(offset, resetPageOffset) - } else { - textChapter.setProgressListener(object : LayoutProgressListener { - override fun onLayoutPageCompleted(index: Int, page: TextPage) { - if (index > 1) { - return - } - callBack?.upContent(offset, resetPageOffset) + textChapter.setProgressListener(object : LayoutProgressListener { + override fun onLayoutPageCompleted(index: Int, page: TextPage) { + if (index > 1) { + return } - }) - } + callBack?.upContent(offset, resetPageOffset) + } + }) } } } - Unit + textChapter.createLayout(this@ReadBook, book, contents) }.onError { AppLog.put("ChapterProvider ERROR", it) appCtx.toastOnUi("ChapterProvider ERROR:\n${it.stackTraceStr}") diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index c08339218..a668377d6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -288,6 +288,10 @@ class PageView(context: Context) : FrameLayout(context) { binding.contentTextView.setContent(textPage) } + fun invalidateContentView() { + binding.contentTextView.invalidate() + } + /** * 设置无障碍文本 */ diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index 72896a140..bd7e12b7e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -527,7 +527,11 @@ class ReadView(context: Context, attrs: AttributeSet) : curPage.setContentDescription(pageFactory.curPage.text) } if (isScroll && !isAutoPage) { - curPage.setContent(pageFactory.curPage, resetPageOffset) + if (relativePosition == 0) { + curPage.setContent(pageFactory.curPage, resetPageOffset) + } else { + curPage.invalidateContentView() + } } else { when (relativePosition) { -1 -> prevPage.setContent(pageFactory.prevPage) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 8b88fa75e..8e4fa240d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -32,7 +32,6 @@ import io.legado.app.utils.postEvent import io.legado.app.utils.spToPx import io.legado.app.utils.splitNotBlank import io.legado.app.utils.textHeight -import kotlinx.coroutines.CoroutineScope import splitties.init.appCtx import java.util.LinkedList import java.util.Locale @@ -307,12 +306,10 @@ object ChapterProvider { } fun getTextChapterAsync( - book: Book, bookChapter: BookChapter, displayTitle: String, bookContent: BookContent, chapterSize: Int, - scope: CoroutineScope ): TextChapter { val textChapter = TextChapter( @@ -323,9 +320,7 @@ object ChapterProvider { bookChapter.isVip, bookChapter.isPay, bookContent.effectiveReplaceRules - ).apply { - createLayout(scope, book, bookContent) - } + ) return textChapter } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt index 3ab22cad6..3a2f4f486 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt @@ -13,7 +13,6 @@ import io.legado.app.help.book.BookHelp import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.coroutine.Coroutine -import io.legado.app.help.globalExecutor import io.legado.app.model.ImageProvider import io.legado.app.model.ReadBook import io.legado.app.ui.book.read.page.entities.TextChapter @@ -69,7 +68,7 @@ class TextChapterLayout( private val stringBuilder = StringBuilder() private var isCompleted = false - private var job: Coroutine<*>? = null + private val job: Coroutine<*> private val bookChapter inline get() = textChapter.chapter private val displayTitle inline get() = textChapter.title private val chaptersSize inline get() = textChapter.chaptersSize @@ -77,19 +76,17 @@ class TextChapterLayout( var exception: Throwable? = null init { - globalExecutor.submit { - job = Coroutine.async(scope) { - launch { - val bookSource = book.getBookSource() ?: return@launch - BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString()) - } - getTextChapter(book, bookChapter, displayTitle, bookContent) - }.onError { - exception = it - onException(it) - }.onFinally { - isCompleted = true + job = Coroutine.async(scope) { + launch { + val bookSource = book.getBookSource() ?: return@launch + BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString()) } + getTextChapter(book, bookChapter, displayTitle, bookContent) + }.onError { + exception = it + onException(it) + }.onFinally { + isCompleted = true } } @@ -109,7 +106,7 @@ class TextChapterLayout( } fun cancel() { - job?.cancel() + job.cancel() } private fun onPageCompleted() { From 00a42a05ef172142d841b2d0fd49fbed312b9758 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Thu, 22 Feb 2024 17:15:55 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/model/ReadBook.kt | 3 --- .../io/legado/app/ui/book/read/page/entities/TextChapter.kt | 1 + .../legado/app/ui/book/read/page/provider/TextChapterLayout.kt | 1 + 3 files changed, 2 insertions(+), 3 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 e5af2b870..f0b144b27 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -216,7 +216,6 @@ object ReadBook : CoroutineScope by MainScope() { durChapterPos = 0 durChapterIndex++ prevTextChapter?.cancelLayout() - curTextChapter?.setProgressListener(null) prevTextChapter = curTextChapter curTextChapter = nextTextChapter nextTextChapter = null @@ -250,7 +249,6 @@ object ReadBook : CoroutineScope by MainScope() { durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: Int.MAX_VALUE else 0 durChapterIndex-- nextTextChapter?.cancelLayout() - curTextChapter?.setProgressListener(null) nextTextChapter = curTextChapter curTextChapter = prevTextChapter prevTextChapter = null @@ -493,7 +491,6 @@ object ReadBook : CoroutineScope by MainScope() { when (val offset = chapter.index - durChapterIndex) { 0 -> { curTextChapter?.cancelLayout() - curTextChapter?.setProgressListener(null) curTextChapter = textChapter if (resetPageOffset) { callBack?.resetPageOffset() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt index 2a5ab7765..6779eca4c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt @@ -295,6 +295,7 @@ data class TextChapter( fun cancelLayout() { layout?.cancel() isCompleted = true + listener = null } companion object { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt index 3a2f4f486..0cb676946 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt @@ -107,6 +107,7 @@ class TextChapterLayout( fun cancel() { job.cancel() + listener = null } private fun onPageCompleted() { From 2d7e3cfe04aad262731abb87b939d8984dc0f4a0 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Thu, 22 Feb 2024 18:35:44 +0800 Subject: [PATCH 5/5] =?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 | 17 +++++++++++++++-- .../legado/app/ui/book/read/ReadBookActivity.kt | 5 +---- .../app/ui/book/read/ReadBookViewModel.kt | 11 +---------- .../app/ui/book/read/page/entities/TextPage.kt | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 16 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 f0b144b27..796cb9b1a 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -294,14 +294,27 @@ object ReadBook : CoroutineScope by MainScope() { curPageChanged(true) } + fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) { + if (index < chapterSize) { + clearTextChapter() + callBack?.upContent() + durChapterIndex = index + ReadBook.durChapterPos = durChapterPos + saveRead() + loadContent(resetPageOffset = true) { + success?.invoke() + } + } + } + /** * 当前页面变化 */ - private fun curPageChanged(pauseReadAloud: Boolean = false) { + private fun curPageChanged(pageChanged: Boolean = false) { callBack?.pageChanged() if (BaseReadAloudService.isRun) { val scrollPageAnim = pageAnim() == 3 - if (scrollPageAnim && pauseReadAloud) { + if (scrollPageAnim && pageChanged) { ReadAloud.pause(appCtx) } else { readAloud(!BaseReadAloudService.pause) 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 33bad1ffa..e84901a42 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 @@ -1381,11 +1381,8 @@ class ReadBookActivity : BaseReadBookActivity(), override fun onLayoutPageCompleted(index: Int, page: TextPage) { upSeekBarThrottle.invoke() if (upContent) { - val line = page.lines.first() val durChapterPos = ReadBook.durChapterPos - val startPos = line.chapterPosition - val endPos = startPos + line.charSize - if (durChapterPos in startPos.. Unit)? = null) { - if (index < ReadBook.chapterSize) { - ReadBook.clearTextChapter() - ReadBook.callBack?.upContent() - ReadBook.durChapterIndex = index - ReadBook.durChapterPos = durChapterPos - ReadBook.saveRead() - ReadBook.loadContent(resetPageOffset = true) { - success?.invoke() - } - } + ReadBook.openChapter(index, durChapterPos, success) } fun removeFromBookshelf(success: (() -> Unit)?) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 9867dcb5f..a787933a2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -47,6 +47,7 @@ data class TextPage( var doublePage = false var paddingTop = 0 var isCompleted = false + @JvmField var textChapter = emptyTextChapter val pageSize get() = textChapter.pageSize @@ -256,6 +257,19 @@ data class TextPage( return textChapter } + /** + * 判断章节字符位置是否在这一页中 + * + * @param chapterPos 章节字符位置 + * @return + */ + fun containPos(chapterPos: Int): Boolean { + val line = lines.first() + val startPos = line.chapterPosition + val endPos = startPos + charSize + return chapterPos in startPos..