修复崩溃bug

pull/811/head
gedoor 4 years ago
parent 0da3abcc88
commit 06d8f16e30
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt
  4. 6
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt

@ -784,7 +784,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
when (requestCode) {
requestCodeEditSource -> viewModel.upBookSource() {
requestCodeEditSource -> viewModel.upBookSource {
upView()
}
requestCodeChapterList ->

@ -347,8 +347,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
selectStart[0] = relativePage
selectStart[1] = lineIndex
selectStart[2] = charIndex
val textLine = relativePage(relativePage).textLines[lineIndex]
val textChar = textLine.textChars[charIndex]
val textLine = relativePage(relativePage).getLine(lineIndex)
val textChar = textLine.getTextChar(charIndex)
upSelectedStart(
textChar.start,
textLine.lineBottom + relativeOffset(relativePage),
@ -364,8 +364,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
selectEnd[0] = relativePage
selectEnd[1] = lineIndex
selectEnd[2] = charIndex
val textLine = relativePage(relativePage).textLines[lineIndex]
val textChar = textLine.textChars[charIndex]
val textLine = relativePage(relativePage).getLine(lineIndex)
val textChar = textLine.getTextChar(lineIndex)
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(relativePage))
upSelectChars()
}

@ -28,8 +28,10 @@ data class TextLine(
textChars.add(TextChar(charData, start = start, end = end))
}
fun getTextCharAt(index: Int): TextChar {
return textChars[index]
fun getTextChar(index: Int): TextChar {
return textChars.getOrElse(index) {
textChars.last()
}
}
fun getTextCharReverseAt(index: Int): TextChar {

@ -25,6 +25,12 @@ data class TextPage(
val lineSize get() = textLines.size
val charSize get() = text.length
fun getLine(index: Int): TextLine {
return textLines.getOrElse(index) {
textLines.last()
}
}
fun upLinesPosition() = ChapterProvider.apply {
if (!ReadBookConfig.textBottomJustify) return@apply
if (textLines.size <= 1) return@apply

Loading…
Cancel
Save