feat: 优化代码

pull/142/head
kunfei 5 years ago
parent 19e2fa92c9
commit 554c388b52
  1. 1
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  2. 16
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt

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

@ -18,6 +18,21 @@ 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)
height += surplus
val tj = surplus / (textLines.size - 1)
if (tj == 0f) return
for (i in 1 until textLines.size) {
val line = textLines[i]
line.lineTop = line.lineTop + tj * i
line.lineBase = line.lineBase + tj * i
line.lineBottom = line.lineBottom + tj * i
}
}
@Suppress("DEPRECATION")
fun format(): TextPage {
if (textLines.isEmpty() && ChapterProvider.visibleWidth > 0) {
@ -101,4 +116,5 @@ data class TextPage(
}
return percent
}
}

Loading…
Cancel
Save