From 72fedba72cdbd435401f28964b4a50509e8ba61e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 22 Feb 2020 18:47:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=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 --- .../app/ui/book/read/page/ContentTextView.kt | 4 ++ .../app/ui/book/read/page/ContentView.kt | 4 ++ .../read/page/delegate/ScrollPageDelegate.kt | 43 +++---------------- 3 files changed, 14 insertions(+), 37 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 99be420ab..fbd4b62be 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 @@ -83,6 +83,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + fun onScroll(offset: Float) { + + } + fun selectText(x: Float, y: Float): Boolean { textPage?.let { textPage -> for ((lineIndex, textLine) in textPage.textLines.withIndex()) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 89a475968..f3171b8d2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -108,6 +108,10 @@ class ContentView(context: Context) : FrameLayout(context) { } } + fun onScroll(offset: Float) { + content_text_view.onScroll(offset) + } + fun upSelectAble(selectAble: Boolean) { content_text_view.selectAble = selectAble } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 3d2af49dd..499b77a80 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -4,12 +4,11 @@ import android.graphics.Canvas import android.view.MotionEvent import android.view.VelocityTracker import io.legado.app.ui.book.read.page.PageView -import kotlin.math.abs class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { // 滑动追踪的时间 - private val VELOCITY_DURATION = 1000 + private val velocityDuration = 1000 //速度追踪器 private val mVelocity: VelocityTracker = VelocityTracker.obtain() @@ -44,42 +43,12 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { distanceY: Float ): Boolean { mVelocity.addMovement(e2) + mVelocity.computeCurrentVelocity(velocityDuration) setTouchPoint(e2.x, e2.y) - if (!isMoved && abs(distanceX) < abs(distanceY)) { - if (distanceY < 0) { - if (atTop) { - //如果上一页不存在 - if (!hasPrev()) { - noNext = true - return true - } - setDirection(Direction.PREV) - setBitmap() - } - } else { - if (atBottom) { - //如果不存在表示没有下一页了 - if (!hasNext()) { - noNext = true - return true - } - setDirection(Direction.NEXT) - setBitmap() - } - } - isMoved = true - } - if ((atTop && mDirection != Direction.PREV) || (atBottom && mDirection != Direction.NEXT) || mDirection == Direction.NONE) { - //传递触摸事件到textView - curPage.dispatchTouchEvent(e2) - } - if (isMoved) { - isCancel = if (mDirection == Direction.NEXT) distanceY < 0 else distanceY > 0 - isRunning = true - //设置触摸点 - setTouchPoint(e2.x, e2.y) - } - return isMoved + + curPage.onScroll(lastY - touchY) + + return true } override fun onFling(