From 082b8503b04b5814473ff63aefccc6221a7474cd Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 18 Dec 2020 22:57:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 2 +- .../io/legado/app/ui/book/read/page/ContentTextView.kt | 9 ++++----- .../java/io/legado/app/ui/book/read/page/PageView.kt | 2 ++ .../legado/app/ui/book/read/page/entities/TextLine.kt | 2 ++ .../legado/app/ui/book/read/page/entities/TextPage.kt | 10 ++++++++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 3de4e9447..d06140a86 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -430,7 +430,7 @@ class ReadBookActivity : ReadBookBaseActivity(), override fun onMenuItemSelected(itemId: Int): Boolean { when (itemId) { R.id.menu_bookmark -> binding.readView.curPage.let { - showBookMark(0, it.selectedText) + showBookMark(it.selectStartPos, it.selectedText) return true } R.id.menu_replace -> { 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 0a6244bb7..847122163 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 @@ -482,12 +482,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val selectStartPos: Int get() { - for (i in 0 until selectStart[0]) { - + val page = relativePage(selectStart[0]) + page.getTextChapter()?.let { + return it.getReadLength(page.index) + + page.getSelectStartLength(selectStart[1], selectStart[2]) } - - - return 0 } 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 e457d5c80..34720e06a 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 @@ -272,5 +272,7 @@ class PageView(context: Context) : FrameLayout(context) { val selectedText: String get() = binding.contentTextView.selectedText + val selectStartPos get() = binding.contentTextView.selectStartPos + val textPage get() = binding.contentTextView.textPage } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 7610ad9d3..d921a217e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -16,6 +16,8 @@ data class TextLine( var isReadAloud: Boolean = false ) { + val charSize: Int get() = textChars.size + fun upTopBottom(durY: Float, textPaint: TextPaint) { lineTop = ChapterProvider.paddingTop + durY lineBottom = lineTop + textPaint.textHeight diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index afc49711e..e2d291141 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -8,6 +8,7 @@ import io.legado.app.help.ReadBookConfig import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.page.provider.ChapterProvider import java.text.DecimalFormat +import kotlin.math.min @Suppress("unused") data class TextPage( @@ -124,6 +125,15 @@ data class TextPage( return percent } + fun getSelectStartLength(lineIndex: Int, charIndex: Int): Int { + var length = 0 + val maxIndex = min(lineIndex, lineSize) + for (index in 0 until maxIndex) { + length += textLines[index].charSize + } + return length + charIndex + } + fun getTextChapter(): TextChapter? { ReadBook.curTextChapter?.let { if (it.position == chapterIndex) {