This commit is contained in:
Horis
2025-07-06 15:30:10 +08:00
parent 5eba29880d
commit 0eb8c3717f
@@ -14,11 +14,12 @@ import io.legado.app.utils.canvasrecorder.recordIfNeeded
/** /**
* 自动翻页 * 自动翻页
*/ */
class AutoPager(private val readView: ReadView) { class AutoPager(private val readView: ReadView) : Runnable {
private var progress = 0 private var progress = 0
var isRunning = false var isRunning = false
private set private set
private var isPausing = false private var isPausing = false
private var isEInkMode = false
private var scrollOffsetRemain = 0.0 private var scrollOffsetRemain = 0.0
private var scrollOffset = 0 private var scrollOffset = 0
private var lastTimeMillis = 0L private var lastTimeMillis = 0L
@@ -28,10 +29,15 @@ class AutoPager(private val readView: ReadView) {
fun start() { fun start() {
isRunning = true isRunning = true
paint.color = ThemeStore.accentColor isEInkMode = AppConfig.isEInkMode
lastTimeMillis = SystemClock.uptimeMillis()
readView.curPage.upSelectAble(false) readView.curPage.upSelectAble(false)
readView.invalidate() if (isEInkMode) {
readView.postDelayed(this, ReadBookConfig.autoReadSpeed * 1000L)
} else {
paint.color = ThemeStore.accentColor
lastTimeMillis = SystemClock.uptimeMillis()
readView.invalidate()
}
} }
fun stop() { fun stop() {
@@ -40,6 +46,8 @@ class AutoPager(private val readView: ReadView) {
} }
isRunning = false isRunning = false
isPausing = false isPausing = false
isEInkMode = false
readView.removeCallbacks(this)
readView.curPage.upSelectAble(AppConfig.textSelectAble) readView.curPage.upSelectAble(AppConfig.textSelectAble)
readView.invalidate() readView.invalidate()
reset() reset()
@@ -51,6 +59,7 @@ class AutoPager(private val readView: ReadView) {
return return
} }
isPausing = true isPausing = true
readView.removeCallbacks(this)
} }
fun resume() { fun resume() {
@@ -58,8 +67,12 @@ class AutoPager(private val readView: ReadView) {
return return
} }
isPausing = false isPausing = false
lastTimeMillis = SystemClock.uptimeMillis() if (isEInkMode) {
readView.invalidate() readView.postDelayed(this, ReadBookConfig.autoReadSpeed * 1000L)
} else {
lastTimeMillis = SystemClock.uptimeMillis()
readView.invalidate()
}
} }
fun reset() { fun reset() {
@@ -75,7 +88,7 @@ class AutoPager(private val readView: ReadView) {
} }
fun onDraw(canvas: Canvas) { fun onDraw(canvas: Canvas) {
if (!isRunning) { if (!isRunning || isEInkMode) {
return return
} }
@@ -106,7 +119,7 @@ class AutoPager(private val readView: ReadView) {
} }
fun computeOffset() { fun computeOffset() {
if (!isRunning || isPausing) { if (!isRunning || isPausing || isEInkMode) {
return return
} }
@@ -134,4 +147,12 @@ class AutoPager(private val readView: ReadView) {
} }
} }
override fun run() {
if (!readView.fillPage(PageDirection.NEXT)) {
stop()
} else {
readView.postDelayed(this, ReadBookConfig.autoReadSpeed * 1000L)
}
}
} }