From 67270fc82447aa388352cd647dd0fa6b2e493c66 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 21 Oct 2020 20:39:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BB=9A=E5=8A=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) 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 295ccb0ef..575279a1c 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 @@ -23,7 +23,9 @@ import io.legado.app.utils.getCompatColor import io.legado.app.utils.getPrefBoolean import kotlinx.coroutines.CoroutineScope - +/** + * 阅读内容界面 + */ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) { var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) var upView: ((TextPage) -> Unit)? = null @@ -41,7 +43,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at //滚动参数 private val pageFactory: TextPageFactory get() = callBack.pageFactory - private val maxScrollOffset = 100f private var pageOffset = 0f init { @@ -173,17 +174,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at */ fun onScroll(mOffset: Float) { if (mOffset == 0f) return - var offset = mOffset - if (offset > maxScrollOffset) { - offset = maxScrollOffset - } else if (offset < -maxScrollOffset) { - offset = -maxScrollOffset - } - - pageOffset += offset + pageOffset += mOffset if (!pageFactory.hasPrev() && pageOffset > 0) { pageOffset = 0f - } else if (!pageFactory.hasNext() && pageOffset < 0) { + } else if (!pageFactory.hasNext() + && pageOffset < 0 + && pageOffset + textPage.height < ChapterProvider.visibleHeight + ) { pageOffset = 0f } else if (pageOffset > 0) { pageFactory.moveToPrev(false) @@ -263,7 +260,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { 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 } selectStart[0] = relativePos @@ -306,7 +306,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (x > textChar.start && x < textChar.end) { Log.e("char", "$relativePos $lineIndex $charIndex") if (selectEnd[0] != relativePos || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { - if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt(selectStart)) { + if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt( + selectStart + ) + ) { return } selectEnd[0] = relativePos