优化
This commit is contained in:
@@ -67,8 +67,6 @@ import io.legado.app.ui.widget.dialog.TextDialog
|
|||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import java.util.*
|
|
||||||
import kotlin.concurrent.timerTask
|
|
||||||
|
|
||||||
|
|
||||||
class ReadBookActivity : BaseReadBookActivity(),
|
class ReadBookActivity : BaseReadBookActivity(),
|
||||||
@@ -154,6 +152,8 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
override val pageFactory: TextPageFactory get() = binding.readView.pageFactory
|
override val pageFactory: TextPageFactory get() = binding.readView.pageFactory
|
||||||
override val headerHeight: Int get() = binding.readView.curPage.headerHeight
|
override val headerHeight: Int get() = binding.readView.curPage.headerHeight
|
||||||
private val menuLayoutIsVisible get() = bottomDialog > 0 || binding.readMenu.isVisible
|
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")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
@@ -414,17 +414,13 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
if (event.action == MotionEvent.ACTION_SCROLL) {
|
if (event.action == MotionEvent.ACTION_SCROLL) {
|
||||||
val axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL)
|
val axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL)
|
||||||
LogUtils.d("onGenericMotionEvent", "axisValue = $axisValue")
|
LogUtils.d("onGenericMotionEvent", "axisValue = $axisValue")
|
||||||
|
mainHandler.removeCallbacks(nextPageRunnable)
|
||||||
|
mainHandler.removeCallbacks(prevPageRunnable)
|
||||||
// 获得垂直坐标上的滚动方向
|
// 获得垂直坐标上的滚动方向
|
||||||
if (axisValue < 0.0f) { // 滚轮向下滚
|
if (axisValue < 0.0f) { // 滚轮向下滚
|
||||||
debounce {
|
mainHandler.postDelayed(nextPageRunnable, 200)
|
||||||
LogUtils.d("onGenericMotionEvent", "down")
|
|
||||||
mouseWheelPage(PageDirection.NEXT)
|
|
||||||
}
|
|
||||||
} else { // 滚轮向上滚
|
} else { // 滚轮向上滚
|
||||||
debounce {
|
mainHandler.postDelayed(prevPageRunnable, 200)
|
||||||
LogUtils.d("onGenericMotionEvent", "up")
|
|
||||||
mouseWheelPage(PageDirection.PREV)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -664,20 +660,6 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
readView.isTextSelected = false
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 鼠标滚轮翻页
|
* 鼠标滚轮翻页
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user