feat: 优化代码

pull/111/head
kunfei 5 years ago
parent 0adf736195
commit 79293667db
  1. 4
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 22
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt

@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.jetbrains.anko.toast
object ReadBook {
@ -283,6 +284,9 @@ object ReadBook {
}
}
}
}.onError {
it.printStackTrace()
App.INSTANCE.toast(it.localizedMessage ?: "ChapterProvider ERROR")
}
}

@ -257,22 +257,24 @@ object ChapterProvider {
if (lineIndex == 0 && layout.lineCount > 1) {
//第一行
var x = 0f
val icw = StaticLayout.getDesiredWidth(bodyIndent, contentPaint)
var x1 = x + icw
val textChar = TextChar(
charData = bodyIndent,
leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom),
rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop)
)
textLine.textChars.add(textChar)
x = x1
val icw = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / bodyIndent.length
for (i in 0..bodyIndent.lastIndex) {
val x1 = x + icw
val textChar = TextChar(
charData = bodyIndent[i].toString(),
leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom),
rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop)
)
textLine.textChars.add(textChar)
x = x1
}
words = words.replaceFirst(bodyIndent, "")
val gapCount: Int = words.length - 1
val d = (visibleWidth - desiredWidth) / gapCount
for (i in words.indices) {
val char = words[i].toString()
val cw = StaticLayout.getDesiredWidth(char, contentPaint)
x1 = if (i != words.lastIndex) x + cw + d else x + cw
val x1 = if (i != words.lastIndex) x + cw + d else x + cw
val textChar1 = TextChar(
charData = char,
leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom),

@ -207,12 +207,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (lineIndex == selectLineStart && lineIndex == selectLineEnd) {
stringBuilder.append(
it.textLines[lineIndex].text.substring(
selectCharStart + 1,
selectCharEnd + 2
selectCharStart,
selectCharEnd + 1
)
)
} else if (lineIndex == selectLineStart) {
stringBuilder.append(it.textLines[lineIndex].text.substring(selectCharStart + 1))
stringBuilder.append(it.textLines[lineIndex].text.substring(selectCharStart))
} else if (lineIndex == selectLineEnd) {
stringBuilder.append(
it.textLines[lineIndex].text.substring(0, selectCharEnd + 1)

Loading…
Cancel
Save