feat: 优化代码

pull/106/head
kunfei 5 years ago
parent 5e7f27f56b
commit 40452715e7
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt

@ -88,12 +88,16 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
fun selectText(x: Float, y: Float): SelectPoint? { fun selectText(x: Float, y: Float): SelectPoint? {
textPage?.let { textPage -> textPage?.let { textPage ->
for (textLine in textPage.textLines) { for ((lineIndex, textLine) in textPage.textLines.withIndex()) {
if (y > textLine.lineTop && y < textLine.lineBottom) { if (y > textLine.lineTop && y < textLine.lineBottom) {
for (textChar in textLine.textChars) { for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) {
textChar.selected = true textChar.selected = true
invalidate() invalidate()
selectStartLine = lineIndex
selectStartChar = charIndex
selectEndLine = lineIndex
selectEndChar = charIndex
return SelectPoint( return SelectPoint(
textChar.leftBottomPosition.x, textChar.leftBottomPosition.x,
textChar.leftBottomPosition.y.toFloat(), textChar.leftBottomPosition.y.toFloat(),

Loading…
Cancel
Save