From 589fe363e6631f10289236976c55f6a803de64bf Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 May 2022 22:23:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BF=BB=E9=A1=B5=E5=8A=A8?= =?UTF-8?q?=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/PageView.kt | 19 +++++++++++++++---- .../page/delegate/HorizontalPageDelegate.kt | 8 ++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index b030ed118..0e85d9c35 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -10,6 +10,7 @@ import androidx.core.view.isGone import androidx.core.view.isInvisible import io.legado.app.R import io.legado.app.constant.AppConst.timeFormat +import io.legado.app.constant.AppLog import io.legado.app.data.entities.Bookmark import io.legado.app.databinding.ViewBookPageBinding import io.legado.app.help.config.ReadBookConfig @@ -43,8 +44,7 @@ class PageView(context: Context) : FrameLayout(context) { private var tvTimeBattery: BatteryView? = null private var tvTimeBatteryP: BatteryView? = null - var bitmap: Bitmap? = null - private set + private var bitmap: Bitmap? = null val headerHeight: Int get() { @@ -64,11 +64,22 @@ class PageView(context: Context) : FrameLayout(context) { } } + fun getBitmap(): Bitmap? { + synchronized(this) { + return bitmap + } + } + private fun upBitmap() { Coroutine.async { val screenshot = screenshot() - bitmap?.recycle() - bitmap = screenshot + val tmp = bitmap + synchronized(this@PageView) { + bitmap = screenshot + } + tmp?.recycle() + }.onError { + AppLog.put("更新PageView图片出错", it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 9373ae243..0be97c422 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -20,15 +20,15 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie when (mDirection) { PageDirection.PREV -> { prevBitmap?.recycle() - prevBitmap = prevPage.bitmap?.copy(Bitmap.Config.ARGB_8888, false) + prevBitmap = prevPage.getBitmap()?.copy(Bitmap.Config.ARGB_8888, false) curBitmap?.recycle() - curBitmap = curPage.bitmap?.copy(Bitmap.Config.ARGB_8888, false) + curBitmap = curPage.getBitmap()?.copy(Bitmap.Config.ARGB_8888, false) } PageDirection.NEXT -> { nextBitmap?.recycle() - nextBitmap = nextPage.bitmap?.copy(Bitmap.Config.ARGB_8888, false) + nextBitmap = nextPage.getBitmap()?.copy(Bitmap.Config.ARGB_8888, false) curBitmap?.recycle() - curBitmap = curPage.bitmap?.copy(Bitmap.Config.ARGB_8888, false) + curBitmap = curPage.getBitmap()?.copy(Bitmap.Config.ARGB_8888, false) } else -> Unit }