From 5f9fd9ec9969a4e37f3d9bc01618524d43fc9f2b Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Sep 2019 22:34:37 +0800 Subject: [PATCH] up --- .../legado/app/ui/widget/page/ContentView.kt | 8 ++++++ .../io/legado/app/ui/widget/page/PageView.kt | 1 - .../ui/widget/page/delegate/PageDelegate.kt | 27 ++++++++++++++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt index 121280b9e..747f17497 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt @@ -100,4 +100,12 @@ class ContentView : FrameLayout { tv_bottom_left.text = page?.title tv_bottom_right.text = "${page?.index?.plus(1)}/${page?.pageSize}" } + + fun isTextSelected(): Boolean { + return content_text_view.selectionEnd - content_text_view.selectionStart != 0 + } + + fun contentTextView(): ContentTextView? { + return content_text_view + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 448d7d2d4..85d7be3d1 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -114,7 +114,6 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent): Boolean { - curPage?.dispatchTouchEvent(event) return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event) } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt index 229bfcb48..ce4d4beab 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt @@ -50,6 +50,7 @@ abstract class PageDelegate(protected val pageView: PageView) { var isCancel = false var isRunning = false var isStarted = false + var isLongPress = false protected fun setStartPoint(x: Float, y: Float, invalidate: Boolean = true) { startX = x @@ -154,14 +155,21 @@ abstract class PageDelegate(protected val pageView: PageView) { fun onTouch(event: MotionEvent): Boolean { if (isStarted) return false - - if (isMoved && event.action == MotionEvent.ACTION_UP) { - // 开启翻页效果 - if (!noNext) { - onScrollStart() - } + if (curPage?.isTextSelected() == true) { + curPage?.dispatchTouchEvent(event) return true } + if (event.action == MotionEvent.ACTION_DOWN) { + curPage?.contentTextView()?.setTextIsSelectable(true) + curPage?.dispatchTouchEvent(event) + } else if (event.action == MotionEvent.ACTION_UP) { + curPage?.dispatchTouchEvent(event) + if (isMoved) { + // 开启翻页效果 + if (!noNext) onScrollStart() + return true + } + } return detector.onTouchEvent(event) } @@ -182,6 +190,7 @@ abstract class PageDelegate(protected val pageView: PageView) { private inner class GestureListener : GestureDetector.SimpleOnGestureListener() { override fun onDown(e: MotionEvent): Boolean { + isLongPress = false // abort() //是否移动 isMoved = false @@ -229,7 +238,13 @@ abstract class PageDelegate(protected val pageView: PageView) { return true } + override fun onLongPress(e: MotionEvent?) { + curPage?.dispatchTouchEvent(e) + isLongPress = true + } + override fun onScroll(e1: MotionEvent, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean { + curPage?.contentTextView()?.setTextIsSelectable(false) if (!isMoved && abs(distanceX) > abs(distanceY)) { if (distanceX < 0) { //上一页的参数配置