feat: 优化代码

pull/111/head
kunfei 5 years ago
parent adb84229cc
commit 72fedba72c
  1. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  3. 41
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

@ -83,6 +83,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
}
fun onScroll(offset: Float) {
}
fun selectText(x: Float, y: Float): Boolean {
textPage?.let { textPage ->
for ((lineIndex, textLine) in textPage.textLines.withIndex()) {

@ -108,6 +108,10 @@ class ContentView(context: Context) : FrameLayout(context) {
}
}
fun onScroll(offset: Float) {
content_text_view.onScroll(offset)
}
fun upSelectAble(selectAble: Boolean) {
content_text_view.selectAble = selectAble
}

@ -4,12 +4,11 @@ import android.graphics.Canvas
import android.view.MotionEvent
import android.view.VelocityTracker
import io.legado.app.ui.book.read.page.PageView
import kotlin.math.abs
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
// 滑动追踪的时间
private val VELOCITY_DURATION = 1000
private val velocityDuration = 1000
//速度追踪器
private val mVelocity: VelocityTracker = VelocityTracker.obtain()
@ -44,43 +43,13 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
distanceY: Float
): Boolean {
mVelocity.addMovement(e2)
mVelocity.computeCurrentVelocity(velocityDuration)
setTouchPoint(e2.x, e2.y)
if (!isMoved && abs(distanceX) < abs(distanceY)) {
if (distanceY < 0) {
if (atTop) {
//如果上一页不存在
if (!hasPrev()) {
noNext = true
return true
}
setDirection(Direction.PREV)
setBitmap()
}
} else {
if (atBottom) {
//如果不存在表示没有下一页了
if (!hasNext()) {
noNext = true
curPage.onScroll(lastY - touchY)
return true
}
setDirection(Direction.NEXT)
setBitmap()
}
}
isMoved = true
}
if ((atTop && mDirection != Direction.PREV) || (atBottom && mDirection != Direction.NEXT) || mDirection == Direction.NONE) {
//传递触摸事件到textView
curPage.dispatchTouchEvent(e2)
}
if (isMoved) {
isCancel = if (mDirection == Direction.NEXT) distanceY < 0 else distanceY > 0
isRunning = true
//设置触摸点
setTouchPoint(e2.x, e2.y)
}
return isMoved
}
override fun onFling(
e1: MotionEvent?,

Loading…
Cancel
Save