feat: 优化代码

pull/106/head
kunfei 5 years ago
parent 1b0488c509
commit 0a88f1f6fd
  1. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  2. 37
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt

@ -132,6 +132,8 @@ class PageView(context: Context, attrs: AttributeSet) :
} else {
fillPage(PageDelegate.Direction.PREV)
}
} else {
pageDelegate?.start(PageDelegate.Direction.PREV)
}
}
@ -144,6 +146,8 @@ class PageView(context: Context, attrs: AttributeSet) :
} else {
fillPage(PageDelegate.Direction.NEXT)
}
} else {
pageDelegate?.start(PageDelegate.Direction.NEXT)
}
}

@ -179,23 +179,6 @@ abstract class PageDelegate(protected val pageView: PageView) {
onScrollStart()
}
/**
* 触摸事件处理
*/
@CallSuper
open fun onTouch(event: MotionEvent): Boolean {
if (isStarted) return false
curPage.dispatchTouchEvent(event)
if (event.action == MotionEvent.ACTION_UP) {
if (isMoved) {
// 开启翻页效果
if (!noNext) onScrollStart()
return true
}
}
return detector.onTouchEvent(event)
}
abstract fun onScrollStart()//scroller start
abstract fun onDraw(canvas: Canvas)//绘制
@ -229,6 +212,16 @@ abstract class PageDelegate(protected val pageView: PageView) {
}
}
/**
* 触摸事件处理
*/
@CallSuper
open fun onTouch(event: MotionEvent): Boolean {
if (isStarted) return false
curPage.dispatchTouchEvent(event)
return detector.onTouchEvent(event)
}
/**
* 触摸事件处理
*/
@ -288,6 +281,16 @@ abstract class PageDelegate(protected val pageView: PageView) {
): Boolean {
return this@PageDelegate.onScroll(e1, e2, distanceX, distanceY)
}
override fun onFling(
e1: MotionEvent?,
e2: MotionEvent?,
velocityX: Float,
velocityY: Float
): Boolean {
if (!noNext) onScrollStart()
return true
}
}
fun hasPrev(): Boolean {

Loading…
Cancel
Save