feat: 优化代码

pull/133/head 3.20.030220
kunfei 5 years ago
parent 53f74cbbed
commit 52c366da4f
  1. 51
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt

@ -16,27 +16,11 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
shadowDrawableR.gradientType = GradientDrawable.LINEAR_GRADIENT
}
override fun onAnimStart() {
val distanceX: Float
when (mDirection) {
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)
}
}
startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)
override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) {
curPage.x = 0.toFloat()
prevPage.x = -viewWidth.toFloat()
nextPage.x = 0.toFloat()
super.setStartPoint(x, y, invalidate)
}
override fun onDraw(canvas: Canvas) {
@ -47,7 +31,7 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
) return
val distanceX = if (offsetX > 0) offsetX - viewWidth else offsetX + viewWidth
if (!isMoved) return
if (!isRunning) return
if (mDirection == Direction.PREV) {
prevPage.translationX = offsetX - viewWidth
} else if (mDirection == Direction.NEXT) {
@ -74,4 +58,27 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
}
}
override fun onAnimStart() {
val distanceX: Float
when (mDirection) {
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)
}
}
startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)
}
}

@ -42,7 +42,7 @@ class SlidePageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
|| (mDirection == Direction.PREV && offsetX < 0)
) return
if (!isMoved) return
if (!isRunning) return
if (mDirection == Direction.PREV) {
curPage.translationX = offsetX
prevPage.translationX = offsetX - viewWidth

Loading…
Cancel
Save