From 56531a08df6a5da17cc809eb5edfefccfa58a1da Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 17 Feb 2020 19:03:17 +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 --- .../page/delegate/HorizontalPageDelegate.kt | 7 ++----- .../ui/book/read/page/delegate/PageDelegate.kt | 17 ++++++++++++----- .../read/page/delegate/ScrollPageDelegate.kt | 7 ++----- .../page/delegate/SimulationPageDelegate.kt | 16 +++++++++++++++- 4 files changed, 31 insertions(+), 16 deletions(-) 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 a8037e1cf..f036de572 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 @@ -4,7 +4,6 @@ import android.view.MotionEvent import io.legado.app.constant.PreferKey import io.legado.app.ui.book.read.page.PageView import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.screenshot import kotlin.math.abs abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) { @@ -27,8 +26,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie return true } setDirection(Direction.PREV) - //上一页截图 - bitmap = prevPage.screenshot() + setBitmap() } else { //如果不存在表示没有下一页了 if (!hasNext()) { @@ -36,8 +34,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie return true } setDirection(Direction.NEXT) - //下一页截图 - bitmap = nextPage.screenshot() + setBitmap() } isMoved = true } 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 8b26c29ec..567ba679d 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 @@ -231,10 +231,19 @@ abstract class PageDelegate(protected val pageView: PageView) { NONE, PREV, NEXT } + @CallSuper open fun setDirection(direction: Direction) { mDirection = direction } + open fun setBitmap() { + bitmap = when (mDirection) { + Direction.NEXT -> nextPage.screenshot() + Direction.PREV -> prevPage.screenshot() + else -> null + } + } + /** * 触摸事件处理 */ @@ -264,7 +273,7 @@ abstract class PageDelegate(protected val pageView: PageView) { pageView.callBack?.clickCenter() setTouchPoint(x, y) } else { - bitmap = if (x > viewWidth / 2 || + if (x > viewWidth / 2 || AppConfig.clickAllNext ) { //设置动画方向 @@ -272,15 +281,13 @@ abstract class PageDelegate(protected val pageView: PageView) { return true } setDirection(Direction.PREV) - //下一页截图 - nextPage.screenshot() + setBitmap() } else { if (!hasPrev()) { return true } setDirection(Direction.NEXT) - //上一页截图 - prevPage.screenshot() + setBitmap() } setTouchPoint(x, y) onScrollStart() 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 7360aa203..f6311374d 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 @@ -7,7 +7,6 @@ import android.view.MotionEvent import io.legado.app.constant.PreferKey import io.legado.app.ui.book.read.page.PageView import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.screenshot import kotlin.math.abs class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { @@ -89,8 +88,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { return true } setDirection(Direction.PREV) - //上一页截图 - bitmap = prevPage.screenshot() + setBitmap() } } else { if (atBottom) { @@ -103,8 +101,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { return true } setDirection(Direction.NEXT) - //下一页截图 - bitmap = nextPage.screenshot() + setBitmap() } } isMoved = true 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 464e63ec6..5c0c0d2be 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 @@ -4,6 +4,7 @@ import android.graphics.* import android.graphics.drawable.GradientDrawable import android.os.Build import io.legado.app.ui.book.read.page.PageView +import io.legado.app.utils.screenshot import kotlin.math.* @Suppress("DEPRECATION") @@ -87,7 +88,6 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi override fun setTouchPoint(x: Float, y: Float, invalidate: Boolean) { super.setTouchPoint(x, y, invalidate) //触摸y中间位置吧y变成屏幕高度 - //触摸y中间位置吧y变成屏幕高度 if ((startY > pageView.height / 3.0 && startY < pageView.height * 2 / 3.0) || mDirection == Direction.PREV @@ -123,6 +123,20 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } } + override fun setBitmap() { + when (mDirection) { + Direction.PREV -> { + prevBitmap = prevPage.screenshot() + curBitmap = curPage.screenshot() + } + Direction.NEXT -> { + nextBitmap = nextPage.screenshot() + curBitmap = curPage.screenshot() + } + else -> Unit + } + } + override fun onScrollStart() { val distanceX: Float when (mDirection) {