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 1ee481db5..40bfebede 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 @@ -20,6 +20,8 @@ import io.legado.app.utils.canvasrecorder.recordIfNeeded import io.legado.app.utils.dpToPx import splitties.init.appCtx import java.text.DecimalFormat +import kotlin.math.ceil +import kotlin.math.max import kotlin.math.min /** @@ -178,6 +180,7 @@ data class TextPage( addLine(textLine) } height = ChapterProvider.visibleHeight.toFloat() + upRenderHeight() invalidate() isCompleted = true } @@ -359,4 +362,12 @@ data class TextPage( fun hasImageOrEmpty(): Boolean { return textLines.any { it.isImage } || textLines.isEmpty() } + + fun upRenderHeight() { + renderHeight = ceil(lines.last().lineBottom).toInt() + if (leftLineSize > 0 && leftLineSize != lines.size) { + val leftHeight = ceil(lines[leftLineSize - 1].lineBottom).toInt() + renderHeight = max(renderHeight, leftHeight) + } + } } 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 b5bfa7ee4..856b9fb3e 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 @@ -131,7 +131,7 @@ class TextChapterLayout( private fun onPageCompleted() { val textPage = pendingTextPage - textPage.index = textPages.lastIndex + textPage.index = textPages.size textPage.chapterIndex = bookChapter.index textPage.chapterSize = chaptersSize textPage.title = displayTitle @@ -140,7 +140,7 @@ class TextChapterLayout( textPage.isCompleted = true textPage.textChapter = textChapter textPage.upLinesPosition() - textPage.renderHeight = textPage.lines.maxOf { it.lineBottom.toInt() } + textPage.upRenderHeight() textPages.add(textPage) channel.trySend(textPage) try {