优化翻页动画

pull/1903/head
kunfei 3 years ago
parent 99b12a7d6d
commit 589fe363e6
  1. 19
      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 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)
}
}

@ -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
}

Loading…
Cancel
Save