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 e082a13b6..a8037e1cf 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 @@ -26,6 +26,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie noNext = true return true } + setDirection(Direction.PREV) //上一页截图 bitmap = prevPage.screenshot() } else { @@ -34,6 +35,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie noNext = true return true } + setDirection(Direction.NEXT) //下一页截图 bitmap = nextPage.screenshot() } 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 cba6da6c1..8b26c29ec 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 @@ -47,7 +47,9 @@ abstract class PageDelegate(protected val pageView: PageView) { protected var atTop: Boolean = false protected var atBottom: Boolean = false - private var snackBar: Snackbar? = null + private val snackBar: Snackbar by lazy { + pageView.snackbar("") + } private val scroller: Scroller by lazy { Scroller( @@ -269,12 +271,14 @@ abstract class PageDelegate(protected val pageView: PageView) { if (!hasNext()) { return true } + setDirection(Direction.PREV) //下一页截图 nextPage.screenshot() } else { if (!hasPrev()) { return true } + setDirection(Direction.NEXT) //上一页截图 prevPage.screenshot() } @@ -296,17 +300,11 @@ abstract class PageDelegate(protected val pageView: PageView) { fun hasPrev(): Boolean { //上一页的参数配置 - setDirection(Direction.PREV) val hasPrev = pageView.pageFactory?.hasPrev() == true if (!hasPrev) { - snackBar ?: let { - snackBar = pageView.snackbar("没有上一页") - } - snackBar?.let { - if (!it.isShown) { - it.setText("没有上一页") - it.show() - } + if (!snackBar.isShown) { + snackBar.setText("没有上一页") + snackBar.show() } } return hasPrev @@ -314,17 +312,11 @@ abstract class PageDelegate(protected val pageView: PageView) { fun hasNext(): Boolean { //进行下一页的配置 - setDirection(Direction.NEXT) val hasNext = pageView.pageFactory?.hasNext() == true if (!hasNext) { - snackBar ?: let { - snackBar = pageView.snackbar("没有下一页") - } - snackBar?.let { - if (!it.isShown) { - it.setText("没有下一页") - it.show() - } + if (!snackBar.isShown) { + snackBar.setText("没有下一页") + snackBar.show() } } return hasNext 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 6752153e8..7360aa203 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 @@ -88,6 +88,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { noNext = true return true } + setDirection(Direction.PREV) //上一页截图 bitmap = prevPage.screenshot() } @@ -101,6 +102,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { noNext = true return true } + setDirection(Direction.NEXT) //下一页截图 bitmap = nextPage.screenshot() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index b8e03683c..464e63ec6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -3,9 +3,7 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.* import android.graphics.drawable.GradientDrawable import android.os.Build -import android.view.MotionEvent import io.legado.app.ui.book.read.page.PageView -import io.legado.app.utils.screenshot import kotlin.math.* @Suppress("DEPRECATION") @@ -105,48 +103,6 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } } - override fun onScroll( - e1: MotionEvent, - e2: MotionEvent, - distanceX: Float, - distanceY: Float - ): Boolean { - if (!isMoved) { - val event = e1.toAction(MotionEvent.ACTION_UP) - curPage.dispatchTouchEvent(event) - event.recycle() - if (abs(distanceX) > abs(distanceY)) { - if (distanceX < 0) { - //如果上一页不存在 - if (!hasPrev()) { - noNext = true - return true - } - //上一页截图 - prevBitmap = prevPage.screenshot() - curBitmap = curPage.screenshot() - } else { - //如果不存在表示没有下一页了 - if (!hasNext()) { - noNext = true - return true - } - //下一页截图 - nextBitmap = nextPage.screenshot() - curBitmap = curPage.screenshot() - } - isMoved = true - } - } - if (isMoved) { - isCancel = if (mDirection == Direction.NEXT) distanceX < 0 else distanceX > 0 - isRunning = true - //设置触摸点 - setTouchPoint(e2.x, e2.y) - } - return isMoved - } - override fun setDirection(direction: Direction) { super.setDirection(direction) when (direction) {