feat: 优化代码

pull/172/head
kunfei 5 years ago
parent c2bdea7026
commit bcb78db5e7
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  2. 10
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt

@ -75,7 +75,7 @@ object ChapterProvider {
item.chapterIndex = bookChapter.index item.chapterIndex = bookChapter.index
item.chapterSize = chapterSize item.chapterSize = chapterSize
item.title = bookChapter.title item.title = bookChapter.title
item.upLinesPosition(visibleHeight) item.upLinesPosition()
} }
return TextChapter( return TextChapter(
bookChapter.index, bookChapter.index,

@ -18,11 +18,11 @@ data class TextPage(
var height: Float = 0f var height: Float = 0f
) { ) {
fun upLinesPosition(visibleHeight: Int) { fun upLinesPosition() = ChapterProvider.apply {
if (textLines.size <= 1) return if (textLines.size <= 1) return@apply
if (visibleHeight - height > with(textLines.last()) { lineBottom - lineTop }) return if (visibleHeight - height > with(textLines.last()) { lineBottom - lineTop }) return@apply
val surplus = (visibleHeight - textLines.last().lineBottom) val surplus = (visibleBottom - textLines.last().lineBottom)
if (surplus == 0f) return if (surplus == 0f) return@apply
height += surplus height += surplus
val tj = surplus / (textLines.size - 1) val tj = surplus / (textLines.size - 1)
for (i in 1 until textLines.size) { for (i in 1 until textLines.size) {

Loading…
Cancel
Save