From cf8c7f216bc51197d87bef34a93100211387c617 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 22 Feb 2020 17:32:20 +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 --- .../app/ui/book/read/ReadBookActivity.kt | 13 +++++++---- .../legado/app/ui/book/read/TextActionMenu.kt | 6 ++++- .../legado/app/ui/book/read/page/PageView.kt | 14 +----------- .../read/page/delegate/ScrollPageDelegate.kt | 22 ------------------- 4 files changed, 15 insertions(+), 40 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 5941b588d..7f15d7de7 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 @@ -80,7 +80,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo private var screenTimeOut: Long = 0 private var timeElectricityReceiver: TimeElectricityReceiver? = null - override val headerHeight: Int get() = page_view.headerHeight + override val headerHeight: Int get() = page_view.curPage.headerHeight override fun onActivityCreated(savedInstanceState: Bundle?) { Help.upLayoutInDisplayCutoutMode(window) @@ -323,11 +323,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo when (event.action) { MotionEvent.ACTION_MOVE, MotionEvent.ACTION_UP -> { when (v.id) { - R.id.cursor_left -> page_view.selectStartMove( + R.id.cursor_left -> page_view.curPage.selectStartMove( event.rawX + cursor_left.width, event.rawY - cursor_left.height ) - R.id.cursor_right -> page_view.selectEndMove( + R.id.cursor_right -> page_view.curPage.selectEndMove( event.rawX - cursor_right.width, event.rawY - cursor_right.height ) @@ -385,7 +385,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } - override val selectedText: String get() = page_view.selectedText + override val selectedText: String get() = page_view.curPage.selectedText override fun onMenuItemSelected(item: MenuItemImpl): Boolean { when (item.itemId) { @@ -395,6 +395,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo return false } + override fun onMenuActionFinally() { + textActionMenu?.dismiss() + page_view.pageDelegate?.isTextSelected = false + } + /** * 音量键翻页 */ diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index c86624526..e788d10a7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -70,11 +70,15 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac when (item.itemId) { R.id.menu_copy -> context.sendToClip(callBack.selectedText) } + callBack.onMenuActionFinally() } interface CallBack { - fun onMenuItemSelected(item: MenuItemImpl): Boolean val selectedText: String + + fun onMenuItemSelected(item: MenuItemImpl): Boolean + + fun onMenuActionFinally() } } \ No newline at end of file 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 e95edb355..792d1da55 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 @@ -21,7 +21,7 @@ class PageView(context: Context, attrs: AttributeSet) : var callBack: CallBack? = null var pageFactory: TextPageFactory? = null - private var pageDelegate: PageDelegate? = null + var pageDelegate: PageDelegate? = null var prevPage: ContentView var curPage: ContentView @@ -183,18 +183,6 @@ class PageView(context: Context, attrs: AttributeSet) : nextPage.upBattery(battery) } - fun selectStartMove(x: Float, y: Float) { - curPage.selectStartMove(x, y) - } - - fun selectEndMove(x: Float, y: Float) { - curPage.selectEndMove(x, y) - } - - val headerHeight: Int get() = curPage.headerHeight - - val selectedText: String get() = curPage.selectedText - override val isScrollDelegate: Boolean get() = pageDelegate is ScrollPageDelegate diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 9c9aade48..9c168d207 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -1,15 +1,12 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.Canvas -import android.graphics.Matrix import android.view.MotionEvent import io.legado.app.ui.book.read.page.PageView import kotlin.math.abs class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { - private val bitmapMatrix = Matrix() - override fun onAnimStart() { if (!atTop && !atBottom) { stopScroll() @@ -39,26 +36,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } override fun onDraw(canvas: Canvas) { - if (atTop || atBottom) { - val offsetY = touchY - startY - - if ((mDirection == Direction.NEXT && offsetY > 0) - || (mDirection == Direction.PREV && offsetY < 0) - ) return - val distanceY = if (offsetY > 0) offsetY - viewHeight else offsetY + viewHeight - if (atTop && mDirection == Direction.PREV) { - bitmap?.let { - bitmapMatrix.setTranslate(0.toFloat(), distanceY) - canvas.drawBitmap(it, bitmapMatrix, null) - } - } else if (atBottom && mDirection == Direction.NEXT) { - bitmap?.let { - bitmapMatrix.setTranslate(0.toFloat(), distanceY) - canvas.drawBitmap(it, bitmapMatrix, null) - } - } - } } override fun onAnimStop() {