From 7ff0b897187934ae4fb4d46a6e3991ce946dac2b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 16 Apr 2022 12:37:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/info/BookInfoActivity.kt | 2 +- .../app/ui/book/read/page/ContentTextView.kt | 33 ++++++++++++++----- .../legado/app/ui/book/read/page/PageView.kt | 7 ++++ .../legado/app/ui/book/read/page/ReadView.kt | 2 +- .../read => widget/dialog}/PhotoDialog.kt | 2 +- 5 files changed, 34 insertions(+), 12 deletions(-) rename app/src/main/java/io/legado/app/ui/{book/read => widget/dialog}/PhotoDialog.kt (97%) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 86d0b569f..5b437029d 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.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.group.GroupSelectDialog 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.search.SearchActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.toc.TocActivityResult 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.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 17e183146..cda8d3e5d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -12,7 +12,6 @@ import io.legado.app.data.entities.Bookmark import io.legado.app.help.config.ReadBookConfig import io.legado.app.lib.theme.accentColor 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.TextLine 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.ImageProvider import io.legado.app.ui.book.read.page.provider.TextPageFactory +import io.legado.app.ui.widget.dialog.PhotoDialog import io.legado.app.utils.* import kotlin.math.min @@ -217,18 +217,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } /** - * 选择文字 + * */ - fun selectText( + fun longPress( x: Float, y: Float, 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) { activity?.showDialogFragment(PhotoDialog(textPage.chapterIndex, textChar.charData)) } else { + if (!selectAble) return@touch textChar.selected = true invalidate() 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) { - touch(x, y) { relativePos, _, relativeOffset, lineIndex, textLine, charIndex, textChar -> + 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) { @@ -260,7 +275,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 结束选择符移动 */ 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) if (pos.compare(selectEnd) != 0) { if (pos.compare(selectStart) >= 0) { @@ -276,9 +291,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at x: Float, y: Float, touched: ( + relativeOffset: Float, relativePos: Int, textPage: TextPage, - relativeOffset: Float, lineIndex: Int, textLine: TextLine, charIndex: Int, @@ -300,8 +315,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (textChar.isTouch(x)) { touched.invoke( - relativePos, textPage, relativeOffset, + relativePos, textPage, lineIndex, textLine, charIndex, textChar ) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 46ac21f6f..9f1fd01ed 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -260,6 +260,13 @@ class PageView(context: Context) : FrameLayout(context) { 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( x: Float, y: Float, select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index e919798f8..808d30761 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -274,7 +274,7 @@ class ReadView(context: Context, attrs: AttributeSet) : */ private fun onLongPress() { kotlin.runCatching { - curPage.selectText(startX, startY) { relativePos, lineIndex, charIndex -> + curPage.longPress(startX, startY) { relativePos, lineIndex, charIndex -> isTextSelected = true initialTextPos.upData(relativePos, lineIndex, charIndex) val startPos = TextPos(relativePos, lineIndex, charIndex) diff --git a/app/src/main/java/io/legado/app/ui/book/read/PhotoDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/book/read/PhotoDialog.kt rename to app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt index 50eb3a9e5..7d76b2a9a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/PhotoDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.read +package io.legado.app.ui.widget.dialog import android.os.Bundle import android.view.View