Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Nov 10, 2023
1 parent d157bb2 commit 83a264e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,9 @@ class ReadBookActivity : BaseReadBookActivity(),
success: (() -> Unit)?
) {
lifecycleScope.launch {
autoPageProgress = 0
if (relativePosition == 0) {
autoPageProgress = 0
}
binding.readView.upContent(relativePosition, resetPageOffset)
upSeekBarProgress()
loadStates = false
Expand Down Expand Up @@ -964,12 +966,14 @@ class ReadBookActivity : BaseReadBookActivity(),
isAutoPage = false
autoPageRenderer.stop()
binding.readView.invalidate()
binding.readView.clearNextPageBitmap()
binding.readMenu.setAutoPage(false)
upScreenTimeOut()
}
}

private fun autoPagePlus() {
autoPageProgress = 0
autoPageScrollOffset = 0.0
autoPageRenderer.start()
}
Expand Down Expand Up @@ -997,6 +1001,8 @@ class ReadBookActivity : BaseReadBookActivity(),
autoPageProgress = 0
if (!binding.readView.fillPage(PageDirection.NEXT)) {
autoPageStop()
} else {
binding.readView.clearNextPageBitmap()
}
} else {
binding.readView.invalidate()
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
Expand Down Expand Up @@ -97,6 +98,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
private val autoPageRect by lazy { Rect() }
private val autoPagePint by lazy { Paint().apply { color = context.accentColor } }
private val boundary by lazy { BreakIterator.getWordInstance(Locale.getDefault()) }
private var nextPageBitmap: Bitmap? = null

init {
addView(nextPage)
Expand Down Expand Up @@ -141,7 +143,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
pageDelegate?.onDraw(canvas)
if (!isInEditMode && callBack.isAutoPage && !isScroll) {
// 自动翻页
nextPage.screenshot()?.let {
val bitmap = nextPageBitmap ?: nextPage.screenshot()?.also { nextPageBitmap = it }
bitmap?.let {
val bottom = callBack.autoPageProgress
autoPageRect.set(0, 0, width, bottom)
canvas.drawBitmap(it, autoPageRect, autoPageRect, null)
Expand All @@ -152,7 +155,6 @@ class ReadView(context: Context, attrs: AttributeSet) :
bottom.toFloat(),
autoPagePint
)
it.recycle()
}
}
}
Expand Down Expand Up @@ -526,6 +528,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
if (isScroll && !callBack.isAutoPage) {
curPage.setContent(pageFactory.curPage, resetPageOffset)
} else {
if (callBack.isAutoPage && relativePosition >= 0) {
clearNextPageBitmap()
}
when (relativePosition) {
-1 -> prevPage.setContent(pageFactory.prevPage)
1 -> nextPage.setContent(pageFactory.nextPage)
Expand Down Expand Up @@ -628,6 +633,11 @@ class ReadView(context: Context, attrs: AttributeSet) :
return curPage.getCurVisibleFirstLine()?.pagePosition ?: 0
}

fun clearNextPageBitmap() {
nextPageBitmap?.recycle()
nextPageBitmap = null
}

override val currentChapter: TextChapter?
get() {
return if (callBack.isInitFinish) ReadBook.textChapter(0) else null
Expand Down

0 comments on commit 83a264e

Please sign in to comment.