feat: 优化代码

pull/117/head
kunfei 5 years ago
parent 4546a2ad97
commit 1e8bdb489f
  1. 31
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt

@ -471,6 +471,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
val selectedText: String
get() {
val stringBuilder = StringBuilder()
for (relativePos in selectPageStart..selectPageEnd) {
val textPage = relativePage(relativePos)
if (relativePos == selectPageStart && relativePos == selectPageEnd) {
for (lineIndex in selectLineStart..selectLineEnd) {
if (lineIndex == selectLineStart && lineIndex == selectLineEnd) {
stringBuilder.append(
@ -493,6 +496,34 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
stringBuilder.append(textPage.textLines[lineIndex].text)
}
}
} else if (relativePos == selectPageStart) {
for (lineIndex in selectLineStart until relativePage(relativePos).textLines.size) {
if (lineIndex == selectLineStart) {
stringBuilder.append(
textPage.textLines[lineIndex].text.substring(
selectCharStart
)
)
} else {
stringBuilder.append(textPage.textLines[lineIndex].text)
}
}
} else if (relativePos == selectPageEnd) {
for (lineIndex in 0..selectLineEnd) {
if (lineIndex == selectLineEnd) {
stringBuilder.append(
textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1)
)
} else {
stringBuilder.append(textPage.textLines[lineIndex].text)
}
}
} else if (relativePos in selectPageStart + 1 until selectPageEnd) {
for (lineIndex in selectLineStart..selectLineEnd) {
stringBuilder.append(textPage.textLines[lineIndex].text)
}
}
}
return stringBuilder.toString()
}

Loading…
Cancel
Save