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

Loading…
Cancel
Save