优化
This commit is contained in:
@@ -281,16 +281,16 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
fun longPress(
|
fun longPress(
|
||||||
x: Float,
|
x: Float,
|
||||||
y: Float,
|
y: Float,
|
||||||
select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit,
|
select: (textPos: TextPos) -> Unit,
|
||||||
) {
|
) {
|
||||||
touch(x, y) { _, relativePos, _, lineIndex, _, charIndex, textChar ->
|
touch(x, y) { _, textPos, _, _, textChar ->
|
||||||
if (textChar.isImage) {
|
if (textChar.isImage) {
|
||||||
callBack.onImageLongPress(x, y, textChar.charData)
|
callBack.onImageLongPress(x, y, textChar.charData)
|
||||||
} else {
|
} else {
|
||||||
if (!selectAble) return@touch
|
if (!selectAble) return@touch
|
||||||
textChar.selected = true
|
textChar.selected = true
|
||||||
invalidate()
|
invalidate()
|
||||||
select(relativePos, lineIndex, charIndex)
|
select(textPos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,7 +300,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
* @return true:已处理, false:未处理
|
* @return true:已处理, false:未处理
|
||||||
*/
|
*/
|
||||||
fun click(x: Float, y: Float): Boolean {
|
fun click(x: Float, y: Float): Boolean {
|
||||||
touch(x, y) { _, relativePos, textPage, lineIndex, textLine, charIndex, textChar ->
|
touch(x, y) { _, textPos, textPage, textLine, textChar ->
|
||||||
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -312,12 +312,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
fun selectText(
|
fun selectText(
|
||||||
x: Float,
|
x: Float,
|
||||||
y: Float,
|
y: Float,
|
||||||
select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit,
|
select: (textPos: TextPos) -> Unit,
|
||||||
) {
|
) {
|
||||||
touch(x, y) { _, relativePos, _, lineIndex, _, charIndex, textChar ->
|
touch(x, y) { _, textPos, _, _, textChar ->
|
||||||
textChar.selected = true
|
textChar.selected = true
|
||||||
invalidate()
|
invalidate()
|
||||||
select(relativePos, lineIndex, charIndex)
|
select(textPos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,11 +325,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
* 开始选择符移动
|
* 开始选择符移动
|
||||||
*/
|
*/
|
||||||
fun selectStartMove(x: Float, y: Float) {
|
fun selectStartMove(x: Float, y: Float) {
|
||||||
touch(x, y) { relativeOffset, relativePos, _, lineIndex, textLine, charIndex, textChar ->
|
touch(x, y) { relativeOffset, textPos, _, textLine, textChar ->
|
||||||
val pos = TextPos(relativePos, lineIndex, charIndex)
|
if (selectStart.compare(textPos) != 0) {
|
||||||
if (selectStart.compare(pos) != 0) {
|
if (textPos.compare(selectEnd) <= 0) {
|
||||||
if (pos.compare(selectEnd) <= 0) {
|
selectStart.upData(pos = textPos)
|
||||||
selectStart.upData(pos = pos)
|
|
||||||
upSelectedStart(
|
upSelectedStart(
|
||||||
textChar.start,
|
textChar.start,
|
||||||
textLine.lineBottom + relativeOffset,
|
textLine.lineBottom + relativeOffset,
|
||||||
@@ -345,11 +344,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
* 结束选择符移动
|
* 结束选择符移动
|
||||||
*/
|
*/
|
||||||
fun selectEndMove(x: Float, y: Float) {
|
fun selectEndMove(x: Float, y: Float) {
|
||||||
touch(x, y) { relativeOffset, relativePos, _, lineIndex, textLine, charIndex, textChar ->
|
touch(x, y) { relativeOffset, textPos, _, textLine, textChar ->
|
||||||
val pos = TextPos(relativePos, lineIndex, charIndex)
|
if (textPos.compare(selectEnd) != 0) {
|
||||||
if (pos.compare(selectEnd) != 0) {
|
if (textPos.compare(selectStart) >= 0) {
|
||||||
if (pos.compare(selectStart) >= 0) {
|
selectEnd.upData(textPos)
|
||||||
selectEnd.upData(pos)
|
|
||||||
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset)
|
upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset)
|
||||||
upSelectChars()
|
upSelectChars()
|
||||||
}
|
}
|
||||||
@@ -366,11 +364,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
y: Float,
|
y: Float,
|
||||||
touched: (
|
touched: (
|
||||||
relativeOffset: Float,
|
relativeOffset: Float,
|
||||||
relativePos: Int,
|
textPos: TextPos,
|
||||||
textPage: TextPage,
|
textPage: TextPage,
|
||||||
lineIndex: Int,
|
|
||||||
textLine: TextLine,
|
textLine: TextLine,
|
||||||
charIndex: Int,
|
|
||||||
textChar: TextChar
|
textChar: TextChar
|
||||||
) -> Unit
|
) -> Unit
|
||||||
) {
|
) {
|
||||||
@@ -390,9 +386,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
if (textChar.isTouch(x)) {
|
if (textChar.isTouch(x)) {
|
||||||
touched.invoke(
|
touched.invoke(
|
||||||
relativeOffset,
|
relativeOffset,
|
||||||
relativePos, textPage,
|
TextPos(relativePos, lineIndex, charIndex),
|
||||||
lineIndex, textLine,
|
textPage, textLine, textChar
|
||||||
charIndex, textChar
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.legado.app.help.config.ReadTipConfig
|
|||||||
import io.legado.app.model.ReadBook
|
import io.legado.app.model.ReadBook
|
||||||
import io.legado.app.ui.book.read.ReadBookActivity
|
import io.legado.app.ui.book.read.ReadBookActivity
|
||||||
import io.legado.app.ui.book.read.page.entities.TextPage
|
import io.legado.app.ui.book.read.page.entities.TextPage
|
||||||
|
import io.legado.app.ui.book.read.page.entities.TextPos
|
||||||
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||||
import io.legado.app.ui.widget.BatteryView
|
import io.legado.app.ui.widget.BatteryView
|
||||||
import io.legado.app.utils.activity
|
import io.legado.app.utils.activity
|
||||||
@@ -321,7 +322,7 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
*/
|
*/
|
||||||
fun longPress(
|
fun longPress(
|
||||||
x: Float, y: Float,
|
x: Float, y: Float,
|
||||||
select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit,
|
select: (textPos: TextPos) -> Unit,
|
||||||
) {
|
) {
|
||||||
return binding.contentTextView.longPress(x, y - headerHeight, select)
|
return binding.contentTextView.longPress(x, y - headerHeight, select)
|
||||||
}
|
}
|
||||||
@@ -331,7 +332,7 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
*/
|
*/
|
||||||
fun selectText(
|
fun selectText(
|
||||||
x: Float, y: Float,
|
x: Float, y: Float,
|
||||||
select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit,
|
select: (textPos: TextPos) -> Unit,
|
||||||
) {
|
) {
|
||||||
return binding.contentTextView.selectText(x, y - headerHeight, select)
|
return binding.contentTextView.selectText(x, y - headerHeight, select)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -296,18 +296,18 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
*/
|
*/
|
||||||
private fun onLongPress() {
|
private fun onLongPress() {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
curPage.longPress(startX, startY) { relativePos, lineIndex, charIndex ->
|
curPage.longPress(startX, startY) { textPos: TextPos ->
|
||||||
isTextSelected = true
|
isTextSelected = true
|
||||||
pressOnTextSelected = true
|
pressOnTextSelected = true
|
||||||
initialTextPos.upData(relativePos, lineIndex, charIndex)
|
initialTextPos.upData(textPos)
|
||||||
val startPos = TextPos(relativePos, lineIndex, charIndex)
|
val startPos = textPos.copy()
|
||||||
val endPos = TextPos(relativePos, lineIndex, charIndex)
|
val endPos = textPos.copy()
|
||||||
val page = curPage.relativePage(relativePos)
|
val page = curPage.relativePage(textPos.relativePagePos)
|
||||||
val stringBuilder = StringBuilder()
|
val stringBuilder = StringBuilder()
|
||||||
var cIndex = charIndex
|
var cIndex = textPos.charIndex
|
||||||
var lineStart = lineIndex
|
var lineStart = textPos.lineIndex
|
||||||
var lineEnd = lineIndex
|
var lineEnd = textPos.lineIndex
|
||||||
for (index in lineIndex - 1 downTo 0) {
|
for (index in textPos.lineIndex - 1 downTo 0) {
|
||||||
val textLine = page.getLine(index)
|
val textLine = page.getLine(index)
|
||||||
if (textLine.isParagraphEnd) {
|
if (textLine.isParagraphEnd) {
|
||||||
break
|
break
|
||||||
@@ -317,7 +317,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
cIndex += textLine.charSize
|
cIndex += textLine.charSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (index in lineIndex until page.lineSize) {
|
for (index in textPos.lineIndex until page.lineSize) {
|
||||||
val textLine = page.getLine(index)
|
val textLine = page.getLine(index)
|
||||||
stringBuilder.append(textLine.text)
|
stringBuilder.append(textLine.text)
|
||||||
lineEnd += 1
|
lineEnd += 1
|
||||||
@@ -423,11 +423,15 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
* 选择文本
|
* 选择文本
|
||||||
*/
|
*/
|
||||||
private fun selectText(x: Float, y: Float) {
|
private fun selectText(x: Float, y: Float) {
|
||||||
curPage.selectText(x, y) { relativePagePos, lineIndex, charIndex ->
|
curPage.selectText(x, y) { textPos ->
|
||||||
val compare = initialTextPos.compare(relativePagePos, lineIndex, charIndex)
|
val compare = initialTextPos.compare(textPos)
|
||||||
when {
|
when {
|
||||||
compare >= 0 -> {
|
compare >= 0 -> {
|
||||||
curPage.selectStartMoveIndex(relativePagePos, lineIndex, charIndex)
|
curPage.selectStartMoveIndex(
|
||||||
|
textPos.relativePagePos,
|
||||||
|
textPos.lineIndex,
|
||||||
|
textPos.charIndex
|
||||||
|
)
|
||||||
curPage.selectEndMoveIndex(
|
curPage.selectEndMoveIndex(
|
||||||
initialTextPos.relativePagePos,
|
initialTextPos.relativePagePos,
|
||||||
initialTextPos.lineIndex,
|
initialTextPos.lineIndex,
|
||||||
@@ -440,7 +444,11 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
initialTextPos.lineIndex,
|
initialTextPos.lineIndex,
|
||||||
initialTextPos.charIndex
|
initialTextPos.charIndex
|
||||||
)
|
)
|
||||||
curPage.selectEndMoveIndex(relativePagePos, lineIndex, charIndex)
|
curPage.selectEndMoveIndex(
|
||||||
|
textPos.relativePagePos,
|
||||||
|
textPos.lineIndex,
|
||||||
|
textPos.charIndex
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package io.legado.app.ui.book.read.page.entities
|
|||||||
|
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 章节信息
|
||||||
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
data class TextChapter(
|
data class TextChapter(
|
||||||
val position: Int,
|
val position: Int,
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package io.legado.app.ui.book.read.page.entities
|
package io.legado.app.ui.book.read.page.entities
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符信息
|
||||||
|
*/
|
||||||
data class TextChar(
|
data class TextChar(
|
||||||
val charData: String,
|
val charData: String,
|
||||||
var start: Float,
|
var start: Float,
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import android.text.TextPaint
|
|||||||
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||||
import io.legado.app.utils.textHeight
|
import io.legado.app.utils.textHeight
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行信息
|
||||||
|
*/
|
||||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||||
data class TextLine(
|
data class TextLine(
|
||||||
var text: String = "",
|
var text: String = "",
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import splitties.init.appCtx
|
|||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面信息
|
||||||
|
*/
|
||||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||||
data class TextPage(
|
data class TextPage(
|
||||||
var index: Int = 0,
|
var index: Int = 0,
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package io.legado.app.ui.book.read.page.entities
|
package io.legado.app.ui.book.read.page.entities
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 位置信息
|
||||||
|
*/
|
||||||
data class TextPos(
|
data class TextPos(
|
||||||
var relativePagePos: Int,
|
var relativePagePos: Int,
|
||||||
var lineIndex: Int,
|
var lineIndex: Int,
|
||||||
|
|||||||
Reference in New Issue
Block a user