From 1a619e6b6ec6107c2767e7559f95aa607a466ba6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 23 Sep 2019 14:38:54 +0800 Subject: [PATCH] up --- .../widget/page/delegate/CoverPageDelegate.kt | 28 ++++++++++--------- .../ui/widget/page/delegate/PageDelegate.kt | 6 +--- .../page/delegate/ScrollPageDelegate.kt | 28 ++++++++++--------- .../widget/page/delegate/SlidePageDelegate.kt | 28 ++++++++++--------- 4 files changed, 46 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt index 8d1d05e3d..dd4f8d185 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt @@ -21,20 +21,22 @@ class CoverPageDelegate(pageView: PageView) : PageDelegate(pageView) { override fun onScrollStart() { val distanceX: Float when (direction) { - Direction.NEXT -> if (isCancel) { - var dis = viewWidth - startX + touchX - if (dis > viewWidth) { - dis = viewWidth.toFloat() + Direction.NEXT -> distanceX = + if (isCancel) { + var dis = viewWidth - startX + touchX + if (dis > viewWidth) { + dis = viewWidth.toFloat() + } + viewWidth - dis + } else { + -(touchX + (viewWidth - startX)) + } + else -> distanceX = + if (isCancel) { + -(touchX - startX) + } else { + viewWidth - (touchX - startX) } - distanceX = viewWidth - dis - } else { - distanceX = -(touchX + (viewWidth - startX)) - } - else -> distanceX = if (isCancel) { - -(touchX - startX) - } else { - viewWidth - (touchX - startX) - } } startScroll(touchX.toInt(), 0, distanceX.toInt(), 0) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt index 05692299c..56a61ba71 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt @@ -94,7 +94,7 @@ abstract class PageDelegate(protected val pageView: PageView) { startY, dx, dy, - if (dx != 0) getDuration(dx, viewWidth) else getDuration(dy, viewHeight) + if (dx != 0) (dx * 0.3).toInt() else (dy * 0.3).toInt() ) isRunning = true isStarted = true @@ -109,10 +109,6 @@ abstract class PageDelegate(protected val pageView: PageView) { invalidate() } - private fun getDuration(distance: Int, len: Int): Int { - return (300f * abs(distance) / len).toInt() - } - fun setViewSize(width: Int, height: Int) { viewWidth = width viewHeight = height diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/ScrollPageDelegate.kt index b7afc58b6..a2d900529 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/ScrollPageDelegate.kt @@ -15,20 +15,22 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } val distanceY: Float when (direction) { - Direction.NEXT -> if (isCancel) { - var dis = viewHeight - startY + touchY - if (dis > viewHeight) { - dis = viewHeight.toFloat() + 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) } - distanceY = viewHeight - dis - } else { - distanceY = -(touchY + (viewHeight - startY)) - } - else -> distanceY = if (isCancel) { - -(touchY - startY) - } else { - viewWidth - (touchY - startY) - } } startScroll(0, touchY.toInt(), 0, distanceY.toInt()) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt index 584a4aa2e..60cc351f6 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt @@ -11,20 +11,22 @@ class SlidePageDelegate(pageView: PageView) : PageDelegate(pageView) { override fun onScrollStart() { val distanceX: Float when (direction) { - Direction.NEXT -> if (isCancel) { - var dis = viewWidth - startX + touchX - if (dis > viewWidth) { - dis = viewWidth.toFloat() + Direction.NEXT -> distanceX = + if (isCancel) { + var dis = viewWidth - startX + touchX + if (dis > viewWidth) { + dis = viewWidth.toFloat() + } + viewWidth - dis + } else { + -(touchX + (viewWidth - startX)) + } + else -> distanceX = + if (isCancel) { + -(touchX - startX) + } else { + viewWidth - (touchX - startX) } - distanceX = viewWidth - dis - } else { - distanceX = -(touchX + (viewWidth - startX)) - } - else -> distanceX = if (isCancel) { - -(touchX - startX) - } else { - viewWidth - (touchX - startX) - } } startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)