pull/1164/head
gedoor 3 years ago
parent 5636f713c9
commit a4ec93b469
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 31
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt

@ -53,7 +53,6 @@ import io.legado.app.ui.replace.ReplaceRuleActivity
import io.legado.app.ui.replace.edit.ReplaceEditActivity
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -109,7 +108,6 @@ class ReadBookActivity : ReadBookBaseActivity(),
TextActionMenu(this, this)
}
override val scope: CoroutineScope get() = lifecycleScope
override val isInitFinish: Boolean get() = viewModel.isInitFinish
override val isScroll: Boolean get() = binding.readView.isScroll
private val mHandler = Handler(Looper.getMainLooper())

@ -5,7 +5,6 @@ import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.util.Log
import android.view.View
import io.legado.app.R
import io.legado.app.constant.PreferKey
@ -24,7 +23,6 @@ import io.legado.app.utils.activity
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope
import kotlin.math.min
/**
@ -168,9 +166,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
lineBottom: Float,
isImageLine: Boolean
) {
ReadBook.book?.let { book ->
ImageProvider.getImage(book, textPage.chapterIndex, textChar.charData, true)
?.let {
val book = ReadBook.book ?: return
ImageProvider.getImage(book, textPage.chapterIndex, textChar.charData, true)?.let {
val rectF = if (isImageLine) {
RectF(textChar.start, lineTop, textChar.end, lineBottom)
} else {
@ -186,7 +183,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
}
}
}
/**
* 滚动事件
@ -242,9 +238,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
val page = relativePage(relativePos)
for ((lineIndex, textLine) in page.textLines.withIndex()) {
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) {
if (textLine.isTouch(y, relativeOffset)) {
for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (x > textChar.start && x < textChar.end) {
if (textChar.isTouch(x)) {
if (textChar.isImage) {
activity?.supportFragmentManager?.let {
PhotoDialog.show(it, page.chapterIndex, textChar.charData)
@ -278,13 +274,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (relativeOffset >= ChapterProvider.visibleHeight) return
}
for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) {
if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) {
if (textLine.isTouch(y, relativeOffset)) {
for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (x > textChar.start && x < textChar.end) {
if (textChar.isTouch(x)) {
if (selectStart[0] != relativePos || selectStart[1] != lineIndex || selectStart[2] != charIndex) {
if (selectToInt(relativePos, lineIndex, charIndex) > selectToInt(
selectEnd
)
if (selectToInt(relativePos, lineIndex, charIndex)
> selectToInt(selectEnd)
) {
return
}
@ -320,15 +315,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (!callBack.isScroll) return
if (relativeOffset >= ChapterProvider.visibleHeight) return
}
Log.e("y", "$y")
for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) {
if (y > textLine.lineTop + relativeOffset
&& y < textLine.lineBottom + relativeOffset
) {
Log.e("line", "$relativePos $lineIndex")
if (textLine.isTouch(y, relativeOffset)) {
for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (x > textChar.start && x < textChar.end) {
Log.e("char", "$relativePos $lineIndex $charIndex")
if (textChar.isTouch(x)) {
if (selectEnd[0] != relativePos
|| selectEnd[1] != lineIndex
|| selectEnd[2] != charIndex
@ -540,7 +530,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
fun onCancelSelect()
val headerHeight: Int
val pageFactory: TextPageFactory
val scope: CoroutineScope
val isScroll: Boolean
}
}

@ -6,4 +6,10 @@ data class TextChar(
var end: Float,
var selected: Boolean = false,
var isImage: Boolean = false
)
) {
fun isTouch(x: Float): Boolean {
return x > start && x < end
}
}

@ -37,4 +37,8 @@ data class TextLine(
fun getTextCharsCount(): Int {
return textChars.size
}
fun isTouch(y: Float, relativeOffset: Float): Boolean {
return y > lineTop + relativeOffset && y < lineBottom + relativeOffset
}
}

Loading…
Cancel
Save