pull/34/head
kunfei 5 years ago
parent 3a30ee9847
commit 195841d94f
  1. 25
      app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt
  2. 14
      app/src/main/java/io/legado/app/ui/widget/page/delegate/ScrollPageDelegate.kt

@ -38,6 +38,9 @@ abstract class PageDelegate(protected val pageView: PageView) {
protected var viewWidth: Int = pageView.width protected var viewWidth: Int = pageView.width
protected var viewHeight: Int = pageView.height protected var viewHeight: Int = pageView.height
//textView在顶端或低端
protected var atTop: Boolean = false
protected var atBottom: Boolean = false
private val scroller: Scroller by lazy { private val scroller: Scroller by lazy {
Scroller( Scroller(
@ -176,15 +179,21 @@ abstract class PageDelegate(protected val pageView: PageView) {
/** /**
* 触摸事件处理 * 触摸事件处理
*/ */
open fun onTouch(event: MotionEvent): Boolean { fun onTouch(event: MotionEvent): Boolean {
if (isStarted) return false if (isStarted) return false
if (curPage?.isTextSelected() == true) { if (curPage?.isTextSelected() == true) {
curPage?.dispatchTouchEvent(event) curPage?.dispatchTouchEvent(event)
return true return true
} }
if (event.action == MotionEvent.ACTION_DOWN) { if (event.action == MotionEvent.ACTION_DOWN) {
curPage?.contentTextView()?.setTextIsSelectable(true) curPage?.let {
curPage?.dispatchTouchEvent(event) it.contentTextView()?.let { contentTextView ->
contentTextView.setTextIsSelectable(true)
atTop = contentTextView.atTop()
atBottom = contentTextView.atBottom()
}
it.dispatchTouchEvent(event)
}
} else if (event.action == MotionEvent.ACTION_UP) { } else if (event.action == MotionEvent.ACTION_UP) {
curPage?.dispatchTouchEvent(event) curPage?.dispatchTouchEvent(event)
if (isMoved) { if (isMoved) {
@ -276,10 +285,9 @@ abstract class PageDelegate(protected val pageView: PageView) {
} }
} }
if (pageView.isScrollDelegate()) { if (pageView.isScrollDelegate()) {
//传递触摸事件到textView
curPage?.dispatchTouchEvent(e2)
if (!isMoved && abs(distanceX) < abs(distanceY)) { if (!isMoved && abs(distanceX) < abs(distanceY)) {
if (distanceY < 0) { if (distanceY < 0) {
if (atTop) {
//上一页的参数配置 //上一页的参数配置
direction = Direction.PREV direction = Direction.PREV
//判断是否上一页存在 //判断是否上一页存在
@ -291,7 +299,9 @@ abstract class PageDelegate(protected val pageView: PageView) {
} }
//上一页截图 //上一页截图
bitmap = prevPage?.screenshot() bitmap = prevPage?.screenshot()
}
} else { } else {
if (atBottom) {
//进行下一页的配置 //进行下一页的配置
direction = Direction.NEXT direction = Direction.NEXT
//判断是否下一页存在 //判断是否下一页存在
@ -304,8 +314,13 @@ abstract class PageDelegate(protected val pageView: PageView) {
//下一页截图 //下一页截图
bitmap = nextPage?.screenshot() bitmap = nextPage?.screenshot()
} }
}
isMoved = true isMoved = true
} }
if ((atTop && direction != Direction.PREV) || (atBottom && direction != Direction.NEXT) || direction == Direction.NONE) {
//传递触摸事件到textView
curPage?.dispatchTouchEvent(e2)
}
} else if (!isMoved && abs(distanceX) > abs(distanceY)) { } else if (!isMoved && abs(distanceX) > abs(distanceY)) {
if (distanceX < 0) { if (distanceX < 0) {
//上一页的参数配置 //上一页的参数配置

@ -2,23 +2,11 @@ package io.legado.app.ui.widget.page.delegate
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Matrix import android.graphics.Matrix
import android.view.MotionEvent
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
private var atTop: Boolean = false
private var atBottom: Boolean = false
private val bitmapMatrix = Matrix()
override fun onTouch(event: MotionEvent): Boolean { private val bitmapMatrix = Matrix()
if (event.action == MotionEvent.ACTION_DOWN) {
curPage?.contentTextView()?.let {
atTop = it.atTop()
atBottom = it.atBottom()
}
}
return super.onTouch(event)
}
override fun onScrollStart() { override fun onScrollStart() {
if (!atTop && !atBottom) { if (!atTop && !atBottom) {

Loading…
Cancel
Save