pull/34/head
kunfei 5 years ago
parent 4e0ff50777
commit 1a619e6b6e
  1. 10
      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. 12
      app/src/main/java/io/legado/app/ui/widget/page/delegate/ScrollPageDelegate.kt
  4. 10
      app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt

@ -21,16 +21,18 @@ 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 =
if (isCancel) {
var dis = viewWidth - startX + touchX var dis = viewWidth - startX + touchX
if (dis > viewWidth) { if (dis > viewWidth) {
dis = viewWidth.toFloat() dis = viewWidth.toFloat()
} }
distanceX = viewWidth - dis viewWidth - dis
} else { } else {
distanceX = -(touchX + (viewWidth - startX)) -(touchX + (viewWidth - startX))
} }
else -> distanceX = if (isCancel) { else -> distanceX =
if (isCancel) {
-(touchX - startX) -(touchX - startX)
} else { } else {
viewWidth - (touchX - startX) viewWidth - (touchX - startX)

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

@ -11,16 +11,18 @@ 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 =
if (isCancel) {
var dis = viewWidth - startX + touchX var dis = viewWidth - startX + touchX
if (dis > viewWidth) { if (dis > viewWidth) {
dis = viewWidth.toFloat() dis = viewWidth.toFloat()
} }
distanceX = viewWidth - dis viewWidth - dis
} else { } else {
distanceX = -(touchX + (viewWidth - startX)) -(touchX + (viewWidth - startX))
} }
else -> distanceX = if (isCancel) { else -> distanceX =
if (isCancel) {
-(touchX - startX) -(touchX - startX)
} else { } else {
viewWidth - (touchX - startX) viewWidth - (touchX - startX)

Loading…
Cancel
Save