feat: 优化代码

pull/105/head
kunfei 5 years ago
parent 094071ede1
commit e57a981406
  1. 50
      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 水平方向滑动的距离,负值会使滚动向左滚动
if (isCancel) { // dy 垂直方向滑动的距离,负值会使滚动向上滚动
var dis = viewWidth - startX + touchX if (isCancel) {
if (dis > viewWidth) { dx = if (mCornerX > 0 && mDirection == Direction.NEXT) {
dis = viewWidth.toFloat() (viewWidth - touchX)
} } else {
viewWidth - dis -touchX
} else { }
-(touchX + (viewWidth - startX)) if (mDirection != Direction.NEXT) {
} dx = -(viewWidth + touchX)
else -> distanceX = }
if (isCancel) { dy = if (mCornerY > 0) {
-(touchX - startX) (viewHeight - touchY)
} else { } else {
viewWidth - (touchX - startX) -touchY // 防止mTouchY最终变为0
} }
} else {
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