From 06d8f16e3021ed2ebacd6173d1d1ced8ac6c93f7 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 17 Jan 2021 22:19:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B4=A9=E6=BA=83bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/ReadBookActivity.kt | 2 +- .../io/legado/app/ui/book/read/page/ContentTextView.kt | 8 ++++---- .../io/legado/app/ui/book/read/page/entities/TextLine.kt | 6 ++++-- .../io/legado/app/ui/book/read/page/entities/TextPage.kt | 6 ++++++ 4 files changed, 15 insertions(+), 7 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 a0b8ef515..4a2c8db88 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 @@ -784,7 +784,7 @@ class ReadBookActivity : ReadBookBaseActivity(), super.onActivityResult(requestCode, resultCode, data) if (resultCode == Activity.RESULT_OK) { when (requestCode) { - requestCodeEditSource -> viewModel.upBookSource() { + requestCodeEditSource -> viewModel.upBookSource { upView() } requestCodeChapterList -> 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 4d431f8a5..24eebb6d1 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 @@ -347,8 +347,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[0] = relativePage selectStart[1] = lineIndex selectStart[2] = charIndex - val textLine = relativePage(relativePage).textLines[lineIndex] - val textChar = textLine.textChars[charIndex] + val textLine = relativePage(relativePage).getLine(lineIndex) + val textChar = textLine.getTextChar(charIndex) upSelectedStart( textChar.start, textLine.lineBottom + relativeOffset(relativePage), @@ -364,8 +364,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[0] = relativePage selectEnd[1] = lineIndex selectEnd[2] = charIndex - val textLine = relativePage(relativePage).textLines[lineIndex] - val textChar = textLine.textChars[charIndex] + val textLine = relativePage(relativePage).getLine(lineIndex) + val textChar = textLine.getTextChar(lineIndex) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(relativePage)) upSelectChars() } 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 d921a217e..9d73757bb 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 @@ -28,8 +28,10 @@ data class TextLine( textChars.add(TextChar(charData, start = start, end = end)) } - fun getTextCharAt(index: Int): TextChar { - return textChars[index] + fun getTextChar(index: Int): TextChar { + return textChars.getOrElse(index) { + textChars.last() + } } fun getTextCharReverseAt(index: Int): TextChar { 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 e2d291141..ba57dbc48 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 @@ -25,6 +25,12 @@ data class TextPage( val lineSize get() = textLines.size val charSize get() = text.length + fun getLine(index: Int): TextLine { + return textLines.getOrElse(index) { + textLines.last() + } + } + fun upLinesPosition() = ChapterProvider.apply { if (!ReadBookConfig.textBottomJustify) return@apply if (textLines.size <= 1) return@apply