pull/2268/head
kunfei 2 years ago
parent b6baa52d7c
commit 0e2f0c8e7d
  1. 10
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 21
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  3. 14
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt

@ -417,7 +417,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
fun selectStartMoveIndex(relativePagePos: Int, lineIndex: Int, charIndex: Int) { fun selectStartMoveIndex(relativePagePos: Int, lineIndex: Int, charIndex: Int) {
selectStart.relativePagePos = relativePagePos selectStart.relativePagePos = relativePagePos
selectStart.lineIndex = lineIndex selectStart.lineIndex = lineIndex
selectStart.charIndex = charIndex selectStart.columnIndex = charIndex
val textLine = relativePage(relativePagePos).getLine(lineIndex) val textLine = relativePage(relativePagePos).getLine(lineIndex)
val textColumn = textLine.getColumn(charIndex) val textColumn = textLine.getColumn(charIndex)
upSelectedStart( upSelectedStart(
@ -434,7 +434,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) {
selectEnd.relativePagePos = relativePage selectEnd.relativePagePos = relativePage
selectEnd.lineIndex = lineIndex selectEnd.lineIndex = lineIndex
selectEnd.charIndex = charIndex selectEnd.columnIndex = charIndex
val textLine = relativePage(relativePage).getLine(lineIndex) val textLine = relativePage(relativePage).getLine(lineIndex)
val textColumn = textLine.getColumn(charIndex) val textColumn = textLine.getColumn(charIndex)
upSelectedEnd(textColumn.end, textLine.lineBottom + relativeOffset(relativePage)) upSelectedEnd(textColumn.end, textLine.lineBottom + relativeOffset(relativePage))
@ -449,7 +449,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
for ((lineIndex, textLine) in relativePage(relativePos).lines.withIndex()) { for ((lineIndex, textLine) in relativePage(relativePos).lines.withIndex()) {
textPos.lineIndex = lineIndex textPos.lineIndex = lineIndex
for ((charIndex, column) in textLine.columns.withIndex()) { for ((charIndex, column) in textLine.columns.withIndex()) {
textPos.charIndex = charIndex textPos.columnIndex = charIndex
if (column is TextColumn) { if (column is TextColumn) {
column.selected = column.selected =
textPos.compare(selectStart) >= 0 && textPos.compare(selectEnd) <= 0 textPos.compare(selectStart) >= 0 && textPos.compare(selectEnd) <= 0
@ -495,7 +495,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
textPage.lines.forEachIndexed { lineIndex, textLine -> textPage.lines.forEachIndexed { lineIndex, textLine ->
textPos.lineIndex = lineIndex textPos.lineIndex = lineIndex
textLine.columns.forEachIndexed { charIndex, column -> textLine.columns.forEachIndexed { charIndex, column ->
textPos.charIndex = charIndex textPos.columnIndex = charIndex
val compareStart = textPos.compare(selectStart) val compareStart = textPos.compare(selectStart)
val compareEnd = textPos.compare(selectEnd) val compareEnd = textPos.compare(selectEnd)
if (compareStart >= 0 && compareEnd <= 0) { if (compareStart >= 0 && compareEnd <= 0) {
@ -523,7 +523,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
return book.createBookMark().apply { return book.createBookMark().apply {
chapterIndex = page.chapterIndex chapterIndex = page.chapterIndex
chapterPos = chapter.getReadLength(page.index) + chapterPos = chapter.getReadLength(page.index) +
page.getPosByLineColumn(selectStart.lineIndex, selectStart.charIndex) page.getPosByLineColumn(selectStart.lineIndex, selectStart.columnIndex)
chapterName = chapter.title chapterName = chapter.title
bookText = getSelectedText() bookText = getSelectedText()
} }

@ -28,7 +28,6 @@ import io.legado.app.ui.book.read.page.provider.TextPageFactory
import io.legado.app.utils.activity import io.legado.app.utils.activity
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
import io.legado.app.utils.toastOnUi
import java.text.BreakIterator import java.text.BreakIterator
import java.util.* import java.util.*
import kotlin.math.abs import kotlin.math.abs
@ -305,7 +304,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
val endPos = textPos.copy() val endPos = textPos.copy()
val page = curPage.relativePage(textPos.relativePagePos) val page = curPage.relativePage(textPos.relativePagePos)
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
var cIndex = textPos.charIndex var cIndex = textPos.columnIndex
var lineStart = textPos.lineIndex var lineStart = textPos.lineIndex
var lineEnd = textPos.lineIndex var lineEnd = textPos.lineIndex
for (index in textPos.lineIndex - 1 downTo 0) { for (index in textPos.lineIndex - 1 downTo 0) {
@ -345,10 +344,10 @@ class ReadView(context: Context, attrs: AttributeSet) :
for (j in 0 until textLine.charSize) { for (j in 0 until textLine.charSize) {
if (ci == start) { if (ci == start) {
startPos.lineIndex = index startPos.lineIndex = index
startPos.charIndex = j startPos.columnIndex = j
} else if (ci == end - 1) { } else if (ci == end - 1) {
endPos.lineIndex = index endPos.lineIndex = index
endPos.charIndex = j endPos.columnIndex = j
return@run return@run
} }
ci++ ci++
@ -358,12 +357,12 @@ class ReadView(context: Context, attrs: AttributeSet) :
curPage.selectStartMoveIndex( curPage.selectStartMoveIndex(
startPos.relativePagePos, startPos.relativePagePos,
startPos.lineIndex, startPos.lineIndex,
startPos.charIndex startPos.columnIndex
) )
curPage.selectEndMoveIndex( curPage.selectEndMoveIndex(
endPos.relativePagePos, endPos.relativePagePos,
endPos.lineIndex, endPos.lineIndex,
endPos.charIndex endPos.columnIndex
) )
} }
} }
@ -431,24 +430,24 @@ class ReadView(context: Context, attrs: AttributeSet) :
curPage.selectStartMoveIndex( curPage.selectStartMoveIndex(
textPos.relativePagePos, textPos.relativePagePos,
textPos.lineIndex, textPos.lineIndex,
textPos.charIndex textPos.columnIndex
) )
curPage.selectEndMoveIndex( curPage.selectEndMoveIndex(
initialTextPos.relativePagePos, initialTextPos.relativePagePos,
initialTextPos.lineIndex, initialTextPos.lineIndex,
initialTextPos.charIndex initialTextPos.columnIndex
) )
} }
else -> { else -> {
curPage.selectStartMoveIndex( curPage.selectStartMoveIndex(
initialTextPos.relativePagePos, initialTextPos.relativePagePos,
initialTextPos.lineIndex, initialTextPos.lineIndex,
initialTextPos.charIndex initialTextPos.columnIndex
) )
curPage.selectEndMoveIndex( curPage.selectEndMoveIndex(
textPos.relativePagePos, textPos.relativePagePos,
textPos.lineIndex, textPos.lineIndex,
textPos.charIndex textPos.columnIndex
) )
} }
} }
@ -590,7 +589,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
val selectStartPos = curPage.selectStartPos val selectStartPos = curPage.selectStartPos
var pagePos = selectStartPos.relativePagePos var pagePos = selectStartPos.relativePagePos
val line = selectStartPos.lineIndex val line = selectStartPos.lineIndex
val column = selectStartPos.charIndex val column = selectStartPos.columnIndex
while (pagePos > 0) { while (pagePos > 0) {
if (!ReadBook.moveToNextPage()) { if (!ReadBook.moveToNextPage()) {
ReadBook.moveToNextChapter(false) ReadBook.moveToNextChapter(false)

@ -6,19 +6,19 @@ 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,
var charIndex: Int var columnIndex: Int
) { ) {
fun upData(relativePos: Int, lineIndex: Int, charIndex: Int) { fun upData(relativePos: Int, lineIndex: Int, charIndex: Int) {
this.relativePagePos = relativePos this.relativePagePos = relativePos
this.lineIndex = lineIndex this.lineIndex = lineIndex
this.charIndex = charIndex this.columnIndex = charIndex
} }
fun upData(pos: TextPos) { fun upData(pos: TextPos) {
relativePagePos = pos.relativePagePos relativePagePos = pos.relativePagePos
lineIndex = pos.lineIndex lineIndex = pos.lineIndex
charIndex = pos.charIndex columnIndex = pos.columnIndex
} }
fun compare(pos: TextPos): Int { fun compare(pos: TextPos): Int {
@ -27,8 +27,8 @@ data class TextPos(
relativePagePos > pos.relativePagePos -> 3 relativePagePos > pos.relativePagePos -> 3
lineIndex < pos.lineIndex -> -2 lineIndex < pos.lineIndex -> -2
lineIndex > pos.lineIndex -> 2 lineIndex > pos.lineIndex -> 2
charIndex < pos.charIndex -> -1 columnIndex < pos.columnIndex -> -1
charIndex > pos.charIndex -> 1 columnIndex > pos.columnIndex -> 1
else -> 0 else -> 0
} }
} }
@ -39,8 +39,8 @@ data class TextPos(
this.relativePagePos > relativePos -> 3 this.relativePagePos > relativePos -> 3
this.lineIndex < lineIndex -> -2 this.lineIndex < lineIndex -> -2
this.lineIndex > lineIndex -> 2 this.lineIndex > lineIndex -> 2
this.charIndex < charIndex -> -1 this.columnIndex < charIndex -> -1
this.charIndex > charIndex -> 1 this.columnIndex > charIndex -> 1
else -> 0 else -> 0
} }
} }

Loading…
Cancel
Save