edit ReadView.kt

pull/862/head
gedoor 4 years ago
parent b3965be8e7
commit 7482cf8a96
  1. 194
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt

@ -242,104 +242,108 @@ class ReadView(context: Context, attrs: AttributeSet) :
/** /**
* 长按选择 * 长按选择
*/ */
private fun onLongPress() = with(curPage.textPage) { private fun onLongPress() {
curPage.selectText(startX, startY) { relativePage, lineIndex, charIndex -> kotlin.runCatching {
isTextSelected = true with(curPage.textPage) {
firstRelativePage = relativePage curPage.selectText(startX, startY) { relativePage, lineIndex, charIndex ->
firstLineIndex = lineIndex isTextSelected = true
firstCharIndex = charIndex firstRelativePage = relativePage
var lineStart = lineIndex firstLineIndex = lineIndex
var lineEnd = lineIndex firstCharIndex = charIndex
var start: Int var lineStart = lineIndex
var end: Int var lineEnd = lineIndex
if (lineIndex - 1 > 0 && lineIndex + 1 < lineSize) { var start: Int
// 中间行 var end: Int
val lineText = with(textLines) { if (lineIndex - 1 > 0 && lineIndex + 1 < lineSize) {
get(lineIndex - 1).text + get(lineIndex).text + get(lineIndex + 1).text // 中间行
} val lineText = with(textLines) {
boundary.setText(lineText) get(lineIndex - 1).text + get(lineIndex).text + get(lineIndex + 1).text
start = boundary.first() }
end = boundary.next() boundary.setText(lineText)
val cIndex = textLines[lineIndex - 1].text.length + charIndex start = boundary.first()
while (end != BreakIterator.DONE) { end = boundary.next()
if (cIndex in start until end) { val cIndex = textLines[lineIndex - 1].text.length + charIndex
break while (end != BreakIterator.DONE) {
} if (cIndex in start until end) {
start = end break
end = boundary.next() }
} start = end
if (start < textLines[lineIndex - 1].text.length) { end = boundary.next()
lineStart = lineIndex - 1 }
} else { if (start < textLines[lineIndex - 1].text.length) {
start -= textLines[lineIndex - 1].text.length lineStart = lineIndex - 1
} } else {
if (end > textLines[lineIndex - 1].text.length + textLines[lineIndex].text.length) { start -= textLines[lineIndex - 1].text.length
lineEnd = lineIndex + 1 }
end = (end - textLines[lineIndex - 1].text.length if (end > textLines[lineIndex - 1].text.length + textLines[lineIndex].text.length) {
- textLines[lineIndex].text.length) lineEnd = lineIndex + 1
} else { end = (end - textLines[lineIndex - 1].text.length
end = end - textLines[lineIndex - 1].text.length - 1 - textLines[lineIndex].text.length)
} } else {
} else if (lineIndex - 1 > 0) { end = end - textLines[lineIndex - 1].text.length - 1
// 尾行 }
val lineText = with(textLines) { } else if (lineIndex - 1 > 0) {
get(lineIndex - 1).text + get(lineIndex).text // 尾行
} val lineText = with(textLines) {
boundary.setText(lineText) get(lineIndex - 1).text + get(lineIndex).text
start = boundary.first() }
end = boundary.next() boundary.setText(lineText)
val cIndex = textLines[lineIndex - 1].text.length + charIndex start = boundary.first()
while (end != BreakIterator.DONE) { end = boundary.next()
if (cIndex in start until end) { val cIndex = textLines[lineIndex - 1].text.length + charIndex
break while (end != BreakIterator.DONE) {
} if (cIndex in start until end) {
start = end break
end = boundary.next() }
} start = end
if (start < textLines[lineIndex - 1].text.length) { end = boundary.next()
lineStart = lineIndex - 1 }
} else { if (start < textLines[lineIndex - 1].text.length) {
start -= textLines[lineIndex - 1].text.length lineStart = lineIndex - 1
} } else {
end = end - textLines[lineIndex - 1].text.length - 1 start -= textLines[lineIndex - 1].text.length
} else if (lineIndex + 1 < lineSize) { }
// 首行 end = end - textLines[lineIndex - 1].text.length - 1
val lineText = with(textLines) { } else if (lineIndex + 1 < lineSize) {
get(lineIndex).text + get(lineIndex + 1).text // 首行
} val lineText = with(textLines) {
boundary.setText(lineText) get(lineIndex).text + get(lineIndex + 1).text
start = boundary.first() }
end = boundary.next() boundary.setText(lineText)
while (end != BreakIterator.DONE) { start = boundary.first()
if (charIndex in start until end) { end = boundary.next()
break while (end != BreakIterator.DONE) {
} if (charIndex in start until end) {
start = end break
end = boundary.next() }
} start = end
if (end > textLines[lineIndex].text.length) { end = boundary.next()
lineEnd = lineIndex + 1 }
end -= textLines[lineIndex].text.length if (end > textLines[lineIndex].text.length) {
} else { lineEnd = lineIndex + 1
end -= 1 end -= textLines[lineIndex].text.length
} } else {
} else { end -= 1
// 单行 }
val lineText = textLines[lineIndex].text } else {
boundary.setText(lineText) // 单行
start = boundary.first() val lineText = textLines[lineIndex].text
end = boundary.next() boundary.setText(lineText)
while (end != BreakIterator.DONE) { start = boundary.first()
if (charIndex in start until end) { end = boundary.next()
break while (end != BreakIterator.DONE) {
if (charIndex in start until end) {
break
}
start = end
end = boundary.next()
}
end -= 1
} }
start = end curPage.selectStartMoveIndex(firstRelativePage, lineStart, start)
end = boundary.next() curPage.selectEndMoveIndex(firstRelativePage, lineEnd, end)
} }
end -= 1
} }
curPage.selectStartMoveIndex(firstRelativePage, lineStart, start)
curPage.selectEndMoveIndex(firstRelativePage, lineEnd, end)
} }
} }

Loading…
Cancel
Save