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() {
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)

@ -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

@ -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())

@ -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)

Loading…
Cancel
Save