优化翻页动画

pull/1903/head
kunfei 2 years ago
parent 99b12a7d6d
commit 589fe363e6
  1. 17
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt

@ -10,6 +10,7 @@ import androidx.core.view.isGone
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppConst.timeFormat import io.legado.app.constant.AppConst.timeFormat
import io.legado.app.constant.AppLog
import io.legado.app.data.entities.Bookmark import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ViewBookPageBinding import io.legado.app.databinding.ViewBookPageBinding
import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadBookConfig
@ -43,8 +44,7 @@ class PageView(context: Context) : FrameLayout(context) {
private var tvTimeBattery: BatteryView? = null private var tvTimeBattery: BatteryView? = null
private var tvTimeBatteryP: BatteryView? = null private var tvTimeBatteryP: BatteryView? = null
var bitmap: Bitmap? = null private var bitmap: Bitmap? = null
private set
val headerHeight: Int val headerHeight: Int
get() { get() {
@ -64,12 +64,23 @@ class PageView(context: Context) : FrameLayout(context) {
} }
} }
fun getBitmap(): Bitmap? {
synchronized(this) {
return bitmap
}
}
private fun upBitmap() { private fun upBitmap() {
Coroutine.async { Coroutine.async {
val screenshot = screenshot() val screenshot = screenshot()
bitmap?.recycle() val tmp = bitmap
synchronized(this@PageView) {
bitmap = screenshot bitmap = screenshot
} }
tmp?.recycle()
}.onError {
AppLog.put("更新PageView图片出错", it)
}
} }
fun upStyle() = binding.run { fun upStyle() = binding.run {

@ -20,15 +20,15 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
when (mDirection) { when (mDirection) {
PageDirection.PREV -> { PageDirection.PREV -> {
prevBitmap?.recycle() prevBitmap?.recycle()
prevBitmap = prevPage.bitmap?.copy(Bitmap.Config.ARGB_8888, false) prevBitmap = prevPage.getBitmap()?.copy(Bitmap.Config.ARGB_8888, false)
curBitmap?.recycle() curBitmap?.recycle()
curBitmap = curPage.bitmap?.copy(Bitmap.Config.ARGB_8888, false) curBitmap = curPage.getBitmap()?.copy(Bitmap.Config.ARGB_8888, false)
} }
PageDirection.NEXT -> { PageDirection.NEXT -> {
nextBitmap?.recycle() nextBitmap?.recycle()
nextBitmap = nextPage.bitmap?.copy(Bitmap.Config.ARGB_8888, false) nextBitmap = nextPage.getBitmap()?.copy(Bitmap.Config.ARGB_8888, false)
curBitmap?.recycle() curBitmap?.recycle()
curBitmap = curPage.bitmap?.copy(Bitmap.Config.ARGB_8888, false) curBitmap = curPage.getBitmap()?.copy(Bitmap.Config.ARGB_8888, false)
} }
else -> Unit else -> Unit
} }

Loading…
Cancel
Save