优化
This commit is contained in:
@@ -143,7 +143,6 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private var menu: Menu? = null
|
private var menu: Menu? = null
|
||||||
private var autoPageJob: Job? = null
|
|
||||||
private var backupJob: Job? = null
|
private var backupJob: Job? = null
|
||||||
private var keepScreenJon: Job? = null
|
private var keepScreenJon: Job? = null
|
||||||
private var tts: TTS? = null
|
private var tts: TTS? = null
|
||||||
@@ -173,6 +172,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
private var bookChanged = false
|
private var bookChanged = false
|
||||||
private var pageChanged = false
|
private var pageChanged = false
|
||||||
private var reloadContent = false
|
private var reloadContent = false
|
||||||
|
private val autoPageRenderer by lazy { SyncedRenderer { doAutoPage(it) } }
|
||||||
|
|
||||||
//恢复跳转前进度对话框的交互结果
|
//恢复跳转前进度对话框的交互结果
|
||||||
private var confirmRestoreProcess: Boolean? = null
|
private var confirmRestoreProcess: Boolean? = null
|
||||||
@@ -961,7 +961,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
override fun autoPageStop() {
|
override fun autoPageStop() {
|
||||||
if (isAutoPage) {
|
if (isAutoPage) {
|
||||||
isAutoPage = false
|
isAutoPage = false
|
||||||
autoPageJob?.cancel()
|
autoPageRenderer.stop()
|
||||||
binding.readView.invalidate()
|
binding.readView.invalidate()
|
||||||
binding.readMenu.setAutoPage(false)
|
binding.readMenu.setAutoPage(false)
|
||||||
upScreenTimeOut()
|
upScreenTimeOut()
|
||||||
@@ -969,33 +969,27 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun autoPagePlus() {
|
private fun autoPagePlus() {
|
||||||
autoPageJob?.cancel()
|
autoPageRenderer.start()
|
||||||
autoPageJob = lifecycleScope.launch {
|
}
|
||||||
while (isActive) {
|
|
||||||
var delayMillis = ReadBookConfig.autoReadSpeed * 1000L / binding.readView.height
|
private fun doAutoPage(frameTime: Double) {
|
||||||
var scrollOffset = 1
|
if (menuLayoutIsVisible) {
|
||||||
if (delayMillis < 20) {
|
return
|
||||||
var delayInt = delayMillis.toInt()
|
}
|
||||||
if (delayInt == 0) delayInt = 1
|
val readTime = ReadBookConfig.autoReadSpeed * 1000.0
|
||||||
scrollOffset = 20 / delayInt
|
val height = binding.readView.height
|
||||||
delayMillis = 20
|
val scrollOffset = (height / readTime * frameTime).toInt().coerceAtLeast(1)
|
||||||
}
|
if (binding.readView.isScroll) {
|
||||||
delay(delayMillis)
|
binding.readView.curPage.scroll(-scrollOffset)
|
||||||
if (!menuLayoutIsVisible) {
|
} else {
|
||||||
if (binding.readView.isScroll) {
|
autoPageProgress += scrollOffset
|
||||||
binding.readView.curPage.scroll(-scrollOffset)
|
if (autoPageProgress >= height) {
|
||||||
} else {
|
autoPageProgress = 0
|
||||||
autoPageProgress += scrollOffset
|
if (!binding.readView.fillPage(PageDirection.NEXT)) {
|
||||||
if (autoPageProgress >= binding.readView.height) {
|
autoPageStop()
|
||||||
autoPageProgress = 0
|
|
||||||
if (!binding.readView.fillPage(PageDirection.NEXT)) {
|
|
||||||
autoPageStop()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
binding.readView.invalidate()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
binding.readView.invalidate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package io.legado.app.utils
|
||||||
|
|
||||||
|
import android.view.Choreographer
|
||||||
|
|
||||||
|
class SyncedRenderer(val doFrame: (frameTime: Double) -> Unit) {
|
||||||
|
|
||||||
|
private var callback: (Long) -> Unit = {}
|
||||||
|
|
||||||
|
fun start() {
|
||||||
|
var currTime = System.nanoTime() / 1000000.0
|
||||||
|
callback = {
|
||||||
|
val currTimeMs = it / 1000000.0
|
||||||
|
val frameTime = currTimeMs - currTime
|
||||||
|
currTime = currTimeMs
|
||||||
|
doFrame(frameTime)
|
||||||
|
Choreographer.getInstance().postFrameCallback(callback)
|
||||||
|
}
|
||||||
|
Choreographer.getInstance().postFrameCallback(callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop() {
|
||||||
|
Choreographer.getInstance().removeFrameCallback(callback)
|
||||||
|
callback = {}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user