优化翻页

pull/357/head
gedoor 4 years ago
parent e118a309b1
commit e7701895e6
  1. 184
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt

@ -164,7 +164,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
canvas.drawBitmap(it, null, rectF, null) canvas.drawBitmap(it, null, rectF, null)
} }
} }
} }
} }
@ -204,7 +203,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
/** /**
* 选择初始文字 * 选择文字
*/ */
fun selectText( fun selectText(
x: Float, x: Float,
@ -243,7 +242,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
} }
} }
/** /**
@ -251,83 +249,37 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
*/ */
fun selectStartMove(x: Float, y: Float) { fun selectStartMove(x: Float, y: Float) {
if (!visibleRect.contains(x, y)) return if (!visibleRect.contains(x, y)) return
var relativeOffset = relativeOffset(0) var relativeOffset: Float
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { for (relativePos in 0..2) {
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { relativeOffset = relativeOffset(relativePos)
for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (relativePos > 0) {
if (x > textChar.start && x < textChar.end) { //滚动翻页
if (selectStart[0] != 0 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { if (!ReadBookConfig.isScroll) return
if (selectToInt(0, lineIndex, charIndex) > selectToInt(selectEnd)) { if (relativeOffset >= ChapterProvider.visibleHeight) return
return
}
selectStart[0] = 0
selectStart[1] = lineIndex
selectStart[2] = charIndex
upSelectedStart(
textChar.start,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
upSelectChars()
}
return
}
}
return
}
}
if (!ReadBookConfig.isScroll) return
//滚动翻页
relativeOffset = relativeOffset(1)
if (relativeOffset >= ChapterProvider.visibleHeight) return
for ((lineIndex, textLine) in relativePage(1).textLines.withIndex()) {
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) {
for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (x > textChar.start && x < textChar.end) {
if (selectStart[0] != 1 || selectStart[1] != lineIndex || selectStart[2] != charIndex) {
if (selectToInt(1, lineIndex, charIndex) > selectToInt(selectEnd)) {
return
}
selectStart[0] = 1
selectStart[1] = lineIndex
selectStart[2] = charIndex
upSelectedStart(
textChar.start,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
upSelectChars()
}
return
}
}
return
} }
} for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) {
relativeOffset = relativeOffset(2) if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) {
if (relativeOffset >= ChapterProvider.visibleHeight) return for ((charIndex, textChar) in textLine.textChars.withIndex()) {
for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { if (x > textChar.start && x < textChar.end) {
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { if (selectStart[0] != relativePos || selectStart[1] != lineIndex || selectStart[2] != charIndex) {
for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (selectToInt(relativePos, lineIndex, charIndex) > selectToInt(selectEnd)) {
if (x > textChar.start && x < textChar.end) { return
if (selectStart[0] != 2 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { }
if (selectToInt(2, lineIndex, charIndex) > selectToInt(selectEnd)) { selectStart[0] = relativePos
return selectStart[1] = lineIndex
selectStart[2] = charIndex
upSelectedStart(
textChar.start,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
upSelectChars()
} }
selectStart[0] = 2 return
selectStart[1] = lineIndex
selectStart[2] = charIndex
upSelectedStart(
textChar.start,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
upSelectChars()
} }
return
} }
return
} }
return
} }
} }
} }
@ -337,71 +289,33 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
*/ */
fun selectEndMove(x: Float, y: Float) { fun selectEndMove(x: Float, y: Float) {
if (!visibleRect.contains(x, y)) return if (!visibleRect.contains(x, y)) return
var relativeOffset = relativeOffset(0) var relativeOffset: Float
for ((lineIndex, textLine) in textPage.textLines.withIndex()) { for (relativePos in 0..2) {
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { relativeOffset = relativeOffset(relativePos)
for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (relativePos > 0) {
if (x > textChar.start && x < textChar.end) { //滚动翻页
if (selectEnd[0] != 0 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { if (!ReadBookConfig.isScroll) return
if (selectToInt(0, lineIndex, charIndex) < selectToInt(selectStart)) { if (relativeOffset >= ChapterProvider.visibleHeight) return
return
}
selectEnd[0] = 0
selectEnd[1] = lineIndex
selectEnd[2] = charIndex
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset)
upSelectChars()
}
return
}
}
return
}
}
if (!ReadBookConfig.isScroll) return
//滚动翻页
relativeOffset = relativeOffset(1)
if (relativeOffset >= ChapterProvider.visibleHeight) return
for ((lineIndex, textLine) in relativePage(1).textLines.withIndex()) {
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) {
for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (x > textChar.start && x < textChar.end) {
if (selectEnd[0] != 1 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) {
if (selectToInt(1, lineIndex, charIndex) < selectToInt(selectStart)) {
return
}
selectEnd[0] = 1
selectEnd[1] = lineIndex
selectEnd[2] = charIndex
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset)
upSelectChars()
}
return
}
}
return
} }
} for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) {
relativeOffset = relativeOffset(2) if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) {
if (relativeOffset >= ChapterProvider.visibleHeight) return for ((charIndex, textChar) in textLine.textChars.withIndex()) {
for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { if (x > textChar.start && x < textChar.end) {
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { if (selectEnd[0] != relativePos || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) {
for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt(selectStart)) {
if (x > textChar.start && x < textChar.end) { return
if (selectEnd[0] != 2 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { }
if (selectToInt(2, lineIndex, charIndex) < selectToInt(selectStart)) { selectEnd[0] = relativePos
return selectEnd[1] = lineIndex
selectEnd[2] = charIndex
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset)
upSelectChars()
} }
selectEnd[0] = 2 return
selectEnd[1] = lineIndex
selectEnd[2] = charIndex
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset)
upSelectChars()
} }
return
} }
return
} }
return
} }
} }
} }

Loading…
Cancel
Save