From 22f25494d60e15e691e960b77253bebfac0d625b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Sep 2019 17:45:04 +0800 Subject: [PATCH] up --- .../java/io/legado/app/ui/widget/page/ContentTextView.kt | 5 +++++ .../java/io/legado/app/ui/widget/page/ContentView.kt | 9 +++++++++ .../main/java/io/legado/app/ui/widget/page/PageView.kt | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/widget/page/ContentTextView.kt index 7b6665219..7136d6b79 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/ContentTextView.kt @@ -98,6 +98,11 @@ class ContentTextView : AppCompatTextView { mOffsetHeight = mLayoutHeight + totalPaddingTop + totalPaddingBottom - measuredHeight } + override fun scrollTo(x: Int, y: Int) { + setScrollState(scrollStateIdle) + super.scrollTo(x, min(y, mOffsetHeight)) + } + @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent?): Boolean { event?.let { diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt index 8b5185bd9..118bcfa97 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt @@ -134,6 +134,15 @@ class ContentView : FrameLayout { } } + fun scrollToBottom() { + content_text_view.post { + content_text_view.scrollTo( + 0, + content_text_view.layout.getLineTop(content_text_view.lineCount) + ) + } + } + interface CallBack { fun scrollToLine(line: Int) } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 899937b37..114417973 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -70,14 +70,17 @@ class PageView(context: Context, attrs: AttributeSet) : when (direction) { PageDelegate.Direction.PREV -> { it.moveToPrevious() + upContent() + curPage?.scrollToBottom() } PageDelegate.Direction.NEXT -> { it.moveToNext() + upContent() + curPage?.scrollTo(0) } else -> return } } - upContent() } fun upPageAnim() {