pull/34/head
kunfei 5 years ago
parent 4e0ff50777
commit 1a619e6b6e
  1. 28
      app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt
  2. 6
      app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt
  3. 28
      app/src/main/java/io/legado/app/ui/widget/page/delegate/ScrollPageDelegate.kt
  4. 28
      app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt

@ -21,20 +21,22 @@ class CoverPageDelegate(pageView: PageView) : PageDelegate(pageView) {
override fun onScrollStart() { override fun onScrollStart() {
val distanceX: Float val distanceX: Float
when (direction) { when (direction) {
Direction.NEXT -> if (isCancel) { Direction.NEXT -> distanceX =
var dis = viewWidth - startX + touchX if (isCancel) {
if (dis > viewWidth) { var dis = viewWidth - startX + touchX
dis = viewWidth.toFloat() 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) startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)

@ -94,7 +94,7 @@ abstract class PageDelegate(protected val pageView: PageView) {
startY, startY,
dx, dx,
dy, 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 isRunning = true
isStarted = true isStarted = true
@ -109,10 +109,6 @@ abstract class PageDelegate(protected val pageView: PageView) {
invalidate() invalidate()
} }
private fun getDuration(distance: Int, len: Int): Int {
return (300f * abs(distance) / len).toInt()
}
fun setViewSize(width: Int, height: Int) { fun setViewSize(width: Int, height: Int) {
viewWidth = width viewWidth = width
viewHeight = height viewHeight = height

@ -15,20 +15,22 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
} }
val distanceY: Float val distanceY: Float
when (direction) { when (direction) {
Direction.NEXT -> if (isCancel) { Direction.NEXT -> distanceY =
var dis = viewHeight - startY + touchY if (isCancel) {
if (dis > viewHeight) { var dis = viewHeight - startY + touchY
dis = viewHeight.toFloat() 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()) startScroll(0, touchY.toInt(), 0, distanceY.toInt())

@ -11,20 +11,22 @@ class SlidePageDelegate(pageView: PageView) : PageDelegate(pageView) {
override fun onScrollStart() { override fun onScrollStart() {
val distanceX: Float val distanceX: Float
when (direction) { when (direction) {
Direction.NEXT -> if (isCancel) { Direction.NEXT -> distanceX =
var dis = viewWidth - startX + touchX if (isCancel) {
if (dis > viewWidth) { var dis = viewWidth - startX + touchX
dis = viewWidth.toFloat() 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) startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)

Loading…
Cancel
Save