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 2bafc8bd9..1c8a357ff 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -643,12 +643,16 @@ object ReadBook : CoroutineScope by MainScope(), KoinComponent { * chapterOnDur: 0为当前页,1为下一页,-1为上一页 */ fun textChapter(chapterOnDur: Int = 0): TextChapter? { - return when (chapterOnDur) { + val chapter = when (chapterOnDur) { 0 -> curTextChapter 1 -> nextTextChapter -1 -> prevTextChapter else -> null } + if (chapter != null && !chapter.isLayoutSizeMatch()) { + return null + } + return chapter } /** @@ -668,17 +672,25 @@ object ReadBook : CoroutineScope by MainScope(), KoinComponent { } fun loadOrUpContent(success: (() -> Unit)? = null) { - if (curTextChapter == null) { + val curChapter = curTextChapter + if (curChapter == null || !curChapter.isLayoutSizeMatch()) { + curTextChapter = null + nextTextChapter = null + prevTextChapter = null loadContent(durChapterIndex) { success?.invoke() } } else { callBack?.upContent() } - if (nextTextChapter == null) { + val nextChapter = nextTextChapter + if (nextChapter == null || !nextChapter.isLayoutSizeMatch()) { + nextTextChapter = null loadContent(durChapterIndex + 1) } - if (prevTextChapter == null) { + val prevChapter = prevTextChapter + if (prevChapter == null || !prevChapter.isLayoutSizeMatch()) { + prevTextChapter = null loadContent(durChapterIndex - 1) } } 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 1ee0524d6..b15e5c7fc 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 @@ -8,6 +8,7 @@ import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.book.BookContent import io.legado.app.ui.book.read.page.provider.LayoutProgressListener import io.legado.app.ui.book.read.page.provider.TextChapterLayout +import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.utils.fastBinarySearchBy import kotlinx.coroutines.CoroutineScope import kotlin.math.abs @@ -30,6 +31,15 @@ data class TextChapter( val effectiveReplaceRules: List? ) : LayoutProgressListener { + var visibleWidth: Int = 0 + private set + var visibleHeight: Int = 0 + private set + + fun isLayoutSizeMatch(): Boolean { + return visibleWidth == ChapterProvider.visibleWidth && visibleHeight == ChapterProvider.visibleHeight + } + private val textPages = arrayListOf() val pages: List get() = textPages @@ -269,13 +279,16 @@ data class TextChapter( if (layout != null) { throw IllegalStateException("已经排版过了") } - layout = TextChapterLayout( + val textLayout = TextChapterLayout( scope, this, textPages, book, bookContent, ) + layout = textLayout + visibleWidth = textLayout.visibleWidth + visibleHeight = textLayout.visibleHeight } fun setProgressListener(l: LayoutProgressListener?) { 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 b9975da26..eb22a2de2 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 @@ -128,8 +128,8 @@ class TextChapterLayout( private val lineSpacingExtra = ChapterProvider.lineSpacingExtra private val paragraphSpacing = ChapterProvider.paragraphSpacing - private val visibleHeight = ChapterProvider.visibleHeight - private val visibleWidth = ChapterProvider.visibleWidth + internal val visibleHeight = ChapterProvider.visibleHeight + internal val visibleWidth = ChapterProvider.visibleWidth private val viewWidth = ChapterProvider.viewWidth private val doublePage = ChapterProvider.doublePage