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