From 088e5516e0474a958926b4dd7c917a9c3ac64767 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 2 Jul 2022 17:26:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 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 8c514f09c..7e693ce6b 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,8 +67,6 @@ 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(), @@ -154,6 +152,8 @@ class ReadBookActivity : BaseReadBookActivity(), override val pageFactory: TextPageFactory get() = binding.readView.pageFactory override val headerHeight: Int get() = binding.readView.curPage.headerHeight private val menuLayoutIsVisible get() = bottomDialog > 0 || binding.readMenu.isVisible + private val nextPageRunnable by lazy { Runnable { mouseWheelPage(PageDirection.NEXT) } } + private val prevPageRunnable by lazy { Runnable { mouseWheelPage(PageDirection.PREV) } } @SuppressLint("ClickableViewAccessibility") override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -414,17 +414,13 @@ class ReadBookActivity : BaseReadBookActivity(), if (event.action == MotionEvent.ACTION_SCROLL) { val axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL) LogUtils.d("onGenericMotionEvent", "axisValue = $axisValue") + mainHandler.removeCallbacks(nextPageRunnable) + mainHandler.removeCallbacks(prevPageRunnable) // 获得垂直坐标上的滚动方向 if (axisValue < 0.0f) { // 滚轮向下滚 - debounce { - LogUtils.d("onGenericMotionEvent", "down") - mouseWheelPage(PageDirection.NEXT) - } + mainHandler.postDelayed(nextPageRunnable, 200) } else { // 滚轮向上滚 - debounce { - LogUtils.d("onGenericMotionEvent", "up") - mouseWheelPage(PageDirection.PREV) - } + mainHandler.postDelayed(prevPageRunnable, 200) } return true } @@ -664,20 +660,6 @@ 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) - } - } - /** * 鼠标滚轮翻页 */