This commit is contained in:
Horis 2023-11-10 20:53:02 +08:00
parent d157bb2c45
commit 83a264e6ba
2 changed files with 19 additions and 3 deletions

View File

@ -845,7 +845,9 @@ class ReadBookActivity : BaseReadBookActivity(),
success: (() -> Unit)? success: (() -> Unit)?
) { ) {
lifecycleScope.launch { lifecycleScope.launch {
autoPageProgress = 0 if (relativePosition == 0) {
autoPageProgress = 0
}
binding.readView.upContent(relativePosition, resetPageOffset) binding.readView.upContent(relativePosition, resetPageOffset)
upSeekBarProgress() upSeekBarProgress()
loadStates = false loadStates = false
@ -964,12 +966,14 @@ class ReadBookActivity : BaseReadBookActivity(),
isAutoPage = false isAutoPage = false
autoPageRenderer.stop() autoPageRenderer.stop()
binding.readView.invalidate() binding.readView.invalidate()
binding.readView.clearNextPageBitmap()
binding.readMenu.setAutoPage(false) binding.readMenu.setAutoPage(false)
upScreenTimeOut() upScreenTimeOut()
} }
} }
private fun autoPagePlus() { private fun autoPagePlus() {
autoPageProgress = 0
autoPageScrollOffset = 0.0 autoPageScrollOffset = 0.0
autoPageRenderer.start() autoPageRenderer.start()
} }
@ -997,6 +1001,8 @@ class ReadBookActivity : BaseReadBookActivity(),
autoPageProgress = 0 autoPageProgress = 0
if (!binding.readView.fillPage(PageDirection.NEXT)) { if (!binding.readView.fillPage(PageDirection.NEXT)) {
autoPageStop() autoPageStop()
} else {
binding.readView.clearNextPageBitmap()
} }
} else { } else {
binding.readView.invalidate() binding.readView.invalidate()

View File

@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Paint import android.graphics.Paint
import android.graphics.Rect import android.graphics.Rect
@ -97,6 +98,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
private val autoPageRect by lazy { Rect() } private val autoPageRect by lazy { Rect() }
private val autoPagePint by lazy { Paint().apply { color = context.accentColor } } private val autoPagePint by lazy { Paint().apply { color = context.accentColor } }
private val boundary by lazy { BreakIterator.getWordInstance(Locale.getDefault()) } private val boundary by lazy { BreakIterator.getWordInstance(Locale.getDefault()) }
private var nextPageBitmap: Bitmap? = null
init { init {
addView(nextPage) addView(nextPage)
@ -141,7 +143,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
pageDelegate?.onDraw(canvas) pageDelegate?.onDraw(canvas)
if (!isInEditMode && callBack.isAutoPage && !isScroll) { if (!isInEditMode && callBack.isAutoPage && !isScroll) {
// 自动翻页 // 自动翻页
nextPage.screenshot()?.let { val bitmap = nextPageBitmap ?: nextPage.screenshot()?.also { nextPageBitmap = it }
bitmap?.let {
val bottom = callBack.autoPageProgress val bottom = callBack.autoPageProgress
autoPageRect.set(0, 0, width, bottom) autoPageRect.set(0, 0, width, bottom)
canvas.drawBitmap(it, autoPageRect, autoPageRect, null) canvas.drawBitmap(it, autoPageRect, autoPageRect, null)
@ -152,7 +155,6 @@ class ReadView(context: Context, attrs: AttributeSet) :
bottom.toFloat(), bottom.toFloat(),
autoPagePint autoPagePint
) )
it.recycle()
} }
} }
} }
@ -526,6 +528,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
if (isScroll && !callBack.isAutoPage) { if (isScroll && !callBack.isAutoPage) {
curPage.setContent(pageFactory.curPage, resetPageOffset) curPage.setContent(pageFactory.curPage, resetPageOffset)
} else { } else {
if (callBack.isAutoPage && relativePosition >= 0) {
clearNextPageBitmap()
}
when (relativePosition) { when (relativePosition) {
-1 -> prevPage.setContent(pageFactory.prevPage) -1 -> prevPage.setContent(pageFactory.prevPage)
1 -> nextPage.setContent(pageFactory.nextPage) 1 -> nextPage.setContent(pageFactory.nextPage)
@ -628,6 +633,11 @@ class ReadView(context: Context, attrs: AttributeSet) :
return curPage.getCurVisibleFirstLine()?.pagePosition ?: 0 return curPage.getCurVisibleFirstLine()?.pagePosition ?: 0
} }
fun clearNextPageBitmap() {
nextPageBitmap?.recycle()
nextPageBitmap = null
}
override val currentChapter: TextChapter? override val currentChapter: TextChapter?
get() { get() {
return if (callBack.isInitFinish) ReadBook.textChapter(0) else null return if (callBack.isInitFinish) ReadBook.textChapter(0) else null