From dc25ffa3dca4914d761ac95fd99ffb3c4f005583 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 22 Feb 2020 18:55:12 +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 --- .../read/page/delegate/ScrollPageDelegate.kt | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) 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 499b77a80..988b5fc94 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,6 +4,7 @@ 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) { @@ -31,6 +32,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } override fun onDown(e: MotionEvent): Boolean { + abort() mVelocity.clear() mVelocity.addMovement(e) return super.onDown(e) @@ -44,11 +46,36 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { ): Boolean { mVelocity.addMovement(e2) mVelocity.computeCurrentVelocity(velocityDuration) - setTouchPoint(e2.x, e2.y) - curPage.onScroll(lastY - touchY) - - return true + if (!isMoved && abs(distanceX) < abs(distanceY)) { + if (distanceY < 0) { + if (atTop) { + //如果上一页不存在 + if (!hasPrev()) { + noNext = true + return true + } + setDirection(Direction.PREV) + } + } else { + if (atBottom) { + //如果不存在表示没有下一页了 + if (!hasNext()) { + noNext = true + return true + } + setDirection(Direction.NEXT) + } + } + isMoved = true + } + if (isMoved) { + isRunning = true + //设置触摸点 + setTouchPoint(e2.x, e2.y) + curPage.onScroll(lastY - touchY) + } + return isMoved } override fun onFling(