feat: 优化代码

pull/105/head
kunfei 5 years ago
parent 094071ede1
commit e57a981406
  1. 38
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt

@ -138,27 +138,37 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
} }
override fun onScrollStart() { override fun onScrollStart() {
val distanceX: Float var dx: Float
when (mDirection) { val dy: Float
Direction.NEXT -> distanceX = // dx 水平方向滑动的距离,负值会使滚动向左滚动
// dy 垂直方向滑动的距离,负值会使滚动向上滚动
if (isCancel) { if (isCancel) {
var dis = viewWidth - startX + touchX dx = if (mCornerX > 0 && mDirection == Direction.NEXT) {
if (dis > viewWidth) { (viewWidth - touchX)
dis = viewWidth.toFloat() } else {
-touchX
} }
viewWidth - dis if (mDirection != Direction.NEXT) {
dx = -(viewWidth + touchX)
}
dy = if (mCornerY > 0) {
(viewHeight - touchY)
} else { } else {
-(touchX + (viewWidth - startX)) -touchY // 防止mTouchY最终变为0
} }
else -> distanceX =
if (isCancel) {
-(touchX - startX)
} else { } else {
viewWidth - (touchX - startX) dx = if (mCornerX > 0 && mDirection == Direction.NEXT) {
-(viewWidth + touchX)
} else {
(viewWidth - touchX + viewWidth)
}
dy = if (mCornerY > 0) {
(viewHeight - touchY)
} else {
(1 - touchY) // 防止mTouchY最终变为0
} }
} }
startScroll(touchX.toInt(), touchY.toInt(), dx.toInt(), dy.toInt())
startScroll(touchX.toInt(), 0, distanceX.toInt(), 0)
} }
override fun onScrollStop() { override fun onScrollStop() {

Loading…
Cancel
Save