From bcb78db5e78c284aa79bdfa58db4cf562d63ecda Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Mar 2020 21:10:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/ChapterProvider.kt | 2 +- .../legado/app/ui/book/read/page/entities/TextPage.kt | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index b7cf7182e..0d6a0009e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -75,7 +75,7 @@ object ChapterProvider { item.chapterIndex = bookChapter.index item.chapterSize = chapterSize item.title = bookChapter.title - item.upLinesPosition(visibleHeight) + item.upLinesPosition() } return TextChapter( bookChapter.index, 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 6c4e27073..9613947c7 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 @@ -18,11 +18,11 @@ data class TextPage( var height: Float = 0f ) { - fun upLinesPosition(visibleHeight: Int) { - if (textLines.size <= 1) return - if (visibleHeight - height > with(textLines.last()) { lineBottom - lineTop }) return - val surplus = (visibleHeight - textLines.last().lineBottom) - if (surplus == 0f) return + fun upLinesPosition() = ChapterProvider.apply { + if (textLines.size <= 1) return@apply + if (visibleHeight - height > with(textLines.last()) { lineBottom - lineTop }) return@apply + val surplus = (visibleBottom - textLines.last().lineBottom) + if (surplus == 0f) return@apply height += surplus val tj = surplus / (textLines.size - 1) for (i in 1 until textLines.size) {