From 0e55d8910171dd6c2e82506466508b637dee88a3 Mon Sep 17 00:00:00 2001 From: Kevin SuTJ Date: Fri, 1 Jul 2022 16:22:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20"=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E6=BB=9A=E8=BD=AE=E7=BF=BB=E9=A1=B5"=20Add=20'Mouse=20wheel=20?= =?UTF-8?q?page'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 57 +++++++++++++++++++ app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_config_read.xml | 7 +++ 9 files changed, 71 insertions(+) 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 19c686ed1..8c514f09c 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 @@ -67,6 +67,9 @@ import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO +import java.util.* +import kotlin.concurrent.timerTask + class ReadBookActivity : BaseReadBookActivity(), View.OnTouchListener, @@ -403,6 +406,32 @@ class ReadBookActivity : BaseReadBookActivity(), return super.dispatchKeyEvent(event) } + /** + * 鼠标滚轮事件 + */ + override fun onGenericMotionEvent(event: MotionEvent): Boolean { + if (0 != (event.source and InputDevice.SOURCE_CLASS_POINTER)) { + if (event.action == MotionEvent.ACTION_SCROLL) { + val axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL) + LogUtils.d("onGenericMotionEvent", "axisValue = $axisValue") + // 获得垂直坐标上的滚动方向 + if (axisValue < 0.0f) { // 滚轮向下滚 + debounce { + LogUtils.d("onGenericMotionEvent", "down") + mouseWheelPage(PageDirection.NEXT) + } + } else { // 滚轮向上滚 + debounce { + LogUtils.d("onGenericMotionEvent", "up") + mouseWheelPage(PageDirection.PREV) + } + } + return true + } + } + return super.onGenericMotionEvent(event) + } + /** * 按键事件 */ @@ -635,6 +664,34 @@ class ReadBookActivity : BaseReadBookActivity(), readView.isTextSelected = false } + /** + * 防抖函数 + */ + private var timer: Timer? = null + private fun debounce(doThing: () -> Unit) { + timer?.cancel() + timer = Timer().apply { + schedule(timerTask { + doThing.invoke() + timer = null + }, 200) + } + } + + /** + * 鼠标滚轮翻页 + */ + private fun mouseWheelPage(direction: PageDirection): Boolean { + if (!binding.readMenu.isVisible) { + if (getPrefBoolean("mouseWheelPage", true)) { + binding.readView.pageDelegate?.isCancel = false + binding.readView.pageDelegate?.keyTurnPage(direction) + return true + } + } + return false + } + /** * 音量键翻页 */ diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 3c902c6a9..26fe3f5bc 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -192,6 +192,7 @@ Portada Libro Botones de volumen para pasar página + Rueda del ratón para pasar página Toque la pantalla para pasar página Animación de hojeada Animación de hojeada (libro) diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index a1a09f6f7..4b808acec 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -196,6 +196,7 @@ Cover Book Volume keys to turn page + Mouse wheel to turn page Tap screen to turn page Flip animation Flip animation (book) diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index a3d9f12c5..ce063bdc8 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -196,6 +196,7 @@ Capa Livro Botões de volume para virar páginas + Rolagem do mouse para virar páginas Toque a tela para virar página Virar animação Virar animação (livro) diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 8bd464fcb..e766a58d6 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -193,6 +193,7 @@ 封面 音量鍵翻頁 + 鼠标滚动翻页 點擊翻頁 翻頁動畫 翻頁動畫(本書) diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 9ac815bf4..cede2c668 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -195,6 +195,7 @@ 封面 音量鍵翻頁 + 鼠标滚动翻页 點擊翻頁 翻頁動畫 翻頁動畫(本書) diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 6fd055716..df1d97d84 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -195,6 +195,7 @@ 封面 音量键翻页 + 鼠标滚轮翻页 点击翻页 翻页动画 翻页动画(本书) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d32d7d058..b245e0419 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -196,6 +196,7 @@ Cover Book Volume keys to turn page + Mouse wheel to turn page Tap screen to turn page Flip animation Flip animation (book) diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 1c8a29afb..aeb572e58 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -69,6 +69,13 @@ app:iconSpaceReserved="false" app:isBottomBackground="true" /> + + Date: Fri, 1 Jul 2022 17:08:35 +0800 Subject: [PATCH 2/2] fixed bug: TextView setting 'textIsSelectable=true' make click is invalid --- app/src/main/res/layout/item_read_record.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/layout/item_read_record.xml b/app/src/main/res/layout/item_read_record.xml index e3cd01e07..ef0f5c08c 100644 --- a/app/src/main/res/layout/item_read_record.xml +++ b/app/src/main/res/layout/item_read_record.xml @@ -12,7 +12,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:padding="6dp" - android:textIsSelectable="true" android:textColor="@color/primaryText" android:singleLine="true" app:layout_constraintLeft_toLeftOf="parent"