From ef3049c8d3f22022f186018c3856b287e9741b91 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Mar 2020 22:54:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/ReadBookActivity.kt | 8 ++++---- .../io/legado/app/ui/book/read/page/PageView.kt | 16 ++++++---------- .../ui/book/read/page/delegate/PageDelegate.kt | 13 +++++++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 3ac7715e6..ffdcfcbfc 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -349,7 +349,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo @SuppressLint("ClickableViewAccessibility") override fun onTouch(v: View, event: MotionEvent): Boolean { when (event.action) { - MotionEvent.ACTION_MOVE, MotionEvent.ACTION_UP -> { + MotionEvent.ACTION_DOWN -> textActionMenu?.dismiss() + MotionEvent.ACTION_MOVE -> { when (v.id) { R.id.cursor_left -> page_view.curPage.selectStartMove( event.rawX + cursor_left.width, @@ -361,6 +362,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ) } } + MotionEvent.ACTION_UP -> showTextActionMenu() } return true } @@ -372,7 +374,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo cursor_left.x = x - cursor_left.width cursor_left.y = y cursor_left.visible(true) - showTextActionMenu() } /** @@ -382,7 +383,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo cursor_right.x = x cursor_right.y = y cursor_right.visible(true) - showTextActionMenu() } /** @@ -397,7 +397,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 显示文本操作菜单 */ - private fun showTextActionMenu() { + override fun showTextActionMenu() { textActionMenu ?: let { textActionMenu = TextActionMenu(this, this) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index dbde99c7e..1b7b71b07 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -16,25 +16,20 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), DataSource { - var callBack: CallBack - var pageFactory: TextPageFactory + val callBack: CallBack get() = activity as CallBack + var pageFactory: TextPageFactory = TextPageFactory(this) var pageDelegate: PageDelegate? = null - var prevPage: ContentView - var curPage: ContentView - var nextPage: ContentView + var prevPage: ContentView = ContentView(context) + var curPage: ContentView = ContentView(context) + var nextPage: ContentView = ContentView(context) init { - callBack = activity as CallBack - nextPage = ContentView(context) addView(nextPage) - curPage = ContentView(context) addView(curPage) - prevPage = ContentView(context) addView(prevPage) upBg() setWillNotDraw(false) - pageFactory = TextPageFactory(this) upPageAnim() } @@ -170,5 +165,6 @@ class PageView(context: Context, attrs: AttributeSet) : val isInitFinish: Boolean fun clickCenter() fun screenOffTimerStart() + fun showTextActionMenu() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 4173ffb09..d83f60edb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -200,11 +200,16 @@ abstract class PageDelegate(protected val pageView: PageView) : //GestureDetector.onFling小幅移动不会触发,所以要自己判断 when (event.action) { MotionEvent.ACTION_UP, - MotionEvent.ACTION_CANCEL -> if (isMoved) { - if (selectedOnDown) { - selectedOnDown = false + MotionEvent.ACTION_CANCEL -> { + if (isTextSelected) { + pageView.callBack.showTextActionMenu() + } + if (isMoved) { + if (selectedOnDown) { + selectedOnDown = false + } + if (!noNext) onAnimStart() } - if (!noNext) onAnimStart() } } }