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.chapterSize = chapterSize
item.title = bookChapter.title
item.upLinesPosition(visibleHeight)
item.upLinesPosition()
}
return TextChapter(
bookChapter.index,

@ -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) {

Loading…
Cancel
Save