diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index e92d3cf92..45850cf1c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -200,11 +200,9 @@ class PageView(context: Context, attrs: AttributeSet) : lastY = touchY touchX = x touchY = y - if (invalidate) { invalidate() } - pageDelegate?.onScroll() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index c8d35c173..3ce2dce01 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -37,10 +37,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie override fun onTouch(event: MotionEvent) { when (event.action) { MotionEvent.ACTION_DOWN -> { - if (abort()) { - onAnimStop() - stopScroll() - } + abortAnim() } MotionEvent.ACTION_MOVE -> { onScroll(event) @@ -101,8 +98,16 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie } } + override fun abortAnim() { + if (!scroller.isFinished) { + scroller.abortAnimation() + onAnimStop() + stopScroll() + } + } + override fun nextPageByAnim(animationSpeed: Int) { - abort() + abortAnim() if (!hasNext()) return setDirection(Direction.NEXT) pageView.setTouchPoint(viewWidth.toFloat(), 0f) @@ -110,7 +115,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie } override fun prevPageByAnim(animationSpeed: Int) { - abort() + abortAnim() if (!hasPrev()) return setDirection(Direction.PREV) pageView.setTouchPoint(0f, 0f) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt index a17af92ac..7414df401 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/NoAnimPageDelegate.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.book.read.page.delegate +import android.graphics.Canvas import io.legado.app.ui.book.read.page.PageView class NoAnimPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { @@ -11,4 +12,13 @@ class NoAnimPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) stopScroll() } + override fun onDraw(canvas: Canvas) { + // nothing + } + + override fun onAnimStop() { + // nothing + } + + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 0f4f40669..21dc78dcd 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -35,7 +35,7 @@ abstract class PageDelegate(protected val pageView: PageView) { protected var viewWidth: Int = pageView.width protected var viewHeight: Int = pageView.height - private val scroller: Scroller by lazy { + protected val scroller: Scroller by lazy { Scroller(pageView.context, DecelerateInterpolator()) } @@ -103,21 +103,15 @@ abstract class PageDelegate(protected val pageView: PageView) { } } - fun abort(): Boolean { - if (!scroller.isFinished) { - scroller.abortAnimation() - return true - } - return false - } + open fun onScroll() = Unit - open fun onAnimStart(animationSpeed: Int) {}//scroller start + abstract fun abortAnim() - open fun onDraw(canvas: Canvas) {}//绘制 + abstract fun onAnimStart(animationSpeed: Int) //scroller start - open fun onAnimStop() {}//scroller finish + abstract fun onDraw(canvas: Canvas) //绘制 - open fun onScroll() {}//移动contentView, slidePage + abstract fun onAnimStop() //scroller finish abstract fun nextPageByAnim(animationSpeed: Int) 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 beff7ad7f..a60cad2ee 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 @@ -1,5 +1,6 @@ package io.legado.app.ui.book.read.page.delegate +import android.graphics.Canvas import android.view.MotionEvent import android.view.VelocityTracker import io.legado.app.ui.book.read.page.PageView @@ -20,15 +21,15 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { ) } - override fun onScroll() { - curPage.onScroll(touchY - lastY) + override fun onAnimStop() { + // nothing } override fun onTouch(event: MotionEvent) { when (event.action) { MotionEvent.ACTION_DOWN -> { + abortAnim() pageView.setStartPoint(event.x, event.y) - abort() mVelocity.clear() } MotionEvent.ACTION_MOVE -> { @@ -40,6 +41,14 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } } + override fun onScroll() { + curPage.onScroll(touchY - lastY) + } + + override fun onDraw(canvas: Canvas) { + // nothing + } + private fun onScroll(event: MotionEvent) { mVelocity.addMovement(event) mVelocity.computeCurrentVelocity(velocityDuration) @@ -76,14 +85,20 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { mVelocity.recycle() } + override fun abortAnim() { + if (!scroller.isFinished) { + scroller.abortAnimation() + } + } + override fun nextPageByAnim(animationSpeed: Int) { - abort() + abortAnim() pageView.setStartPoint(0f, 0f, false) startScroll(0, 0, 0, -ChapterProvider.visibleHeight, animationSpeed) } override fun prevPageByAnim(animationSpeed: Int) { - abort() + abortAnim() pageView.setStartPoint(0f, 0f, false) startScroll(0, 0, 0, ChapterProvider.visibleHeight, animationSpeed) }