diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 05b5f6bd9..0d62c791c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -621,6 +621,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo super.onDestroy() mHandler.removeCallbacks(keepScreenRunnable) textActionMenu?.dismiss() + page_view.pageDelegate?.onDestroy() } override fun observeLiveBus() { 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 792d1da55..88d3fb1c1 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 @@ -91,6 +91,7 @@ class PageView(context: Context, attrs: AttributeSet) : } fun upPageAnim(pageAnim: Int) { + pageDelegate?.onDestroy() pageDelegate = null pageDelegate = when (pageAnim) { 0 -> CoverPageDelegate(this) 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 814cfd15c..0c8fa3a3b 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 @@ -323,6 +323,10 @@ abstract class PageDelegate(protected val pageView: PageView) : return hasNext } + open fun onDestroy() { + bitmap?.recycle() + } + enum class Direction { NONE, PREV, NEXT } 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 9c168d207..a3de87a4d 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 @@ -2,37 +2,19 @@ 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 import kotlin.math.abs class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { + // 滑动追踪的时间 + private val VELOCITY_DURATION = 1000 + //速度追踪器 + private val mVelocity: VelocityTracker = VelocityTracker.obtain() + override fun onAnimStart() { - if (!atTop && !atBottom) { - stopScroll() - return - } - val distanceY: Float - when (mDirection) { - Direction.NEXT -> distanceY = - if (isCancel) { - var dis = viewHeight - startY + touchY - if (dis > viewHeight) { - dis = viewHeight.toFloat() - } - viewHeight - dis - } else { - -(touchY + (viewHeight - startY)) - } - else -> distanceY = - if (isCancel) { - -(touchY - startY) - } else { - viewHeight - (touchY - startY) - } - } - startScroll(0, touchY.toInt(), 0, distanceY.toInt()) } override fun onDraw(canvas: Canvas) { @@ -45,6 +27,11 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } } + override fun onDown(e: MotionEvent): Boolean { + mVelocity.clear() + return super.onDown(e) + } + override fun onScroll( e1: MotionEvent, e2: MotionEvent, @@ -94,4 +81,9 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { return isMoved } + + override fun onDestroy() { + super.onDestroy() + mVelocity.recycle() + } } \ No newline at end of file