pull/1794/head
kunfei 3 years ago
parent 53702454a8
commit 7ff0b89718
  1. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 33
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  5. 2
      app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt

@ -30,12 +30,12 @@ import io.legado.app.ui.book.changecover.ChangeCoverDialog
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog import io.legado.app.ui.book.changesource.ChangeBookSourceDialog
import io.legado.app.ui.book.group.GroupSelectDialog import io.legado.app.ui.book.group.GroupSelectDialog
import io.legado.app.ui.book.info.edit.BookInfoEditActivity import io.legado.app.ui.book.info.edit.BookInfoEditActivity
import io.legado.app.ui.book.read.PhotoDialog
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.widget.dialog.PhotoDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO

@ -12,7 +12,6 @@ import io.legado.app.data.entities.Bookmark
import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadBookConfig
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.PhotoDialog
import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextLine
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
@ -20,6 +19,7 @@ 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.book.read.page.provider.ImageProvider import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.ui.book.read.page.provider.TextPageFactory import io.legado.app.ui.book.read.page.provider.TextPageFactory
import io.legado.app.ui.widget.dialog.PhotoDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlin.math.min import kotlin.math.min
@ -217,18 +217,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
/** /**
* 选择文字 *
*/ */
fun selectText( fun longPress(
x: Float, x: Float,
y: Float, y: Float,
select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit, select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit,
) { ) {
if (!selectAble) return touch(x, y) { _, relativePos, textPage, lineIndex, _, charIndex, textChar ->
touch(x, y) { relativePos, textPage, _, lineIndex, _, charIndex, textChar ->
if (textChar.isImage) { if (textChar.isImage) {
activity?.showDialogFragment(PhotoDialog(textPage.chapterIndex, textChar.charData)) activity?.showDialogFragment(PhotoDialog(textPage.chapterIndex, textChar.charData))
} else { } else {
if (!selectAble) return@touch
textChar.selected = true textChar.selected = true
invalidate() invalidate()
select(relativePos, lineIndex, charIndex) select(relativePos, lineIndex, charIndex)
@ -236,11 +236,26 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
} }
/**
* 选择文字
*/
fun selectText(
x: Float,
y: Float,
select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit,
) {
touch(x, y) { _, relativePos, _, lineIndex, _, charIndex, textChar ->
textChar.selected = true
invalidate()
select(relativePos, lineIndex, charIndex)
}
}
/** /**
* 开始选择符移动 * 开始选择符移动
*/ */
fun selectStartMove(x: Float, y: Float) { fun selectStartMove(x: Float, y: Float) {
touch(x, y) { relativePos, _, relativeOffset, lineIndex, textLine, charIndex, textChar -> touch(x, y) { relativeOffset, relativePos, _, lineIndex, textLine, charIndex, textChar ->
val pos = TextPos(relativePos, lineIndex, charIndex) val pos = TextPos(relativePos, lineIndex, charIndex)
if (selectStart.compare(pos) != 0) { if (selectStart.compare(pos) != 0) {
if (pos.compare(selectEnd) <= 0) { if (pos.compare(selectEnd) <= 0) {
@ -260,7 +275,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
* 结束选择符移动 * 结束选择符移动
*/ */
fun selectEndMove(x: Float, y: Float) { fun selectEndMove(x: Float, y: Float) {
touch(x, y) { relativePos, _, relativeOffset, lineIndex, textLine, charIndex, textChar -> touch(x, y) { relativeOffset, relativePos, _, lineIndex, textLine, charIndex, textChar ->
val pos = TextPos(relativePos, lineIndex, charIndex) val pos = TextPos(relativePos, lineIndex, charIndex)
if (pos.compare(selectEnd) != 0) { if (pos.compare(selectEnd) != 0) {
if (pos.compare(selectStart) >= 0) { if (pos.compare(selectStart) >= 0) {
@ -276,9 +291,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
x: Float, x: Float,
y: Float, y: Float,
touched: ( touched: (
relativeOffset: Float,
relativePos: Int, relativePos: Int,
textPage: TextPage, textPage: TextPage,
relativeOffset: Float,
lineIndex: Int, lineIndex: Int,
textLine: TextLine, textLine: TextLine,
charIndex: Int, charIndex: Int,
@ -300,8 +315,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
for ((charIndex, textChar) in textLine.textChars.withIndex()) { for ((charIndex, textChar) in textLine.textChars.withIndex()) {
if (textChar.isTouch(x)) { if (textChar.isTouch(x)) {
touched.invoke( touched.invoke(
relativePos, textPage,
relativeOffset, relativeOffset,
relativePos, textPage,
lineIndex, textLine, lineIndex, textLine,
charIndex, textChar charIndex, textChar
) )

@ -260,6 +260,13 @@ class PageView(context: Context) : FrameLayout(context) {
binding.contentTextView.selectAble = selectAble binding.contentTextView.selectAble = selectAble
} }
fun longPress(
x: Float, y: Float,
select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit,
) {
return binding.contentTextView.longPress(x, y - headerHeight, select)
}
fun selectText( fun selectText(
x: Float, y: Float, x: Float, y: Float,
select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit, select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit,

@ -274,7 +274,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
*/ */
private fun onLongPress() { private fun onLongPress() {
kotlin.runCatching { kotlin.runCatching {
curPage.selectText(startX, startY) { relativePos, lineIndex, charIndex -> curPage.longPress(startX, startY) { relativePos, lineIndex, charIndex ->
isTextSelected = true isTextSelected = true
initialTextPos.upData(relativePos, lineIndex, charIndex) initialTextPos.upData(relativePos, lineIndex, charIndex)
val startPos = TextPos(relativePos, lineIndex, charIndex) val startPos = TextPos(relativePos, lineIndex, charIndex)

@ -1,4 +1,4 @@
package io.legado.app.ui.book.read package io.legado.app.ui.widget.dialog
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
Loading…
Cancel
Save