feat: 优化代码

pull/132/head
kunfei 5 years ago
parent 8c08a6d9e8
commit 37fca1fa83
  1. 24
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt

@ -51,31 +51,17 @@ object ChapterProvider {
val pageLines = arrayListOf<Int>() val pageLines = arrayListOf<Int>()
val pageLengths = arrayListOf<Int>() val pageLengths = arrayListOf<Int>()
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
var surplusText = content val contents = content.split("\n")
var durY = 0f var durY = 0f
textPages.add(TextPage()) textPages.add(TextPage())
while (surplusText.isNotEmpty()) { for ((index, text) in contents.withIndex()) {
if (textPages.first().textLines.isEmpty()) { if (index == 0) {
//title if (ReadBookConfig.titleMode != 2) {
val end = surplusText.indexOf("\n")
if (end > 0) {
val title = surplusText.substring(0, end)
surplusText = surplusText.substring(end + 1)
durY = setTypeText( durY = setTypeText(
title, durY, textPages, pageLines, pageLengths, stringBuilder, true text, durY, textPages, pageLines, pageLengths, stringBuilder, true
) )
} }
} else { } else {
//正文
val end = surplusText.indexOf("\n")
val text: String
if (end >= 0) {
text = surplusText.substring(0, end)
surplusText = surplusText.substring(end + 1)
} else {
text = surplusText
surplusText = ""
}
durY = durY =
setTypeText(text, durY, textPages, pageLines, pageLengths, stringBuilder, false) setTypeText(text, durY, textPages, pageLines, pageLengths, stringBuilder, false)
} }

Loading…
Cancel
Save