Quellcode durchsuchen

优化翻页动画

kunfei vor 4 Jahren
Ursprung
Commit
077879f2fa

+ 15 - 4
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 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 set
+    private var bitmap: Bitmap? = null
 
 
     val headerHeight: Int
     val headerHeight: Int
         get() {
         get() {
@@ -64,11 +64,22 @@ 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()
-            bitmap = screenshot
+            val tmp = bitmap
+            synchronized(this@PageView) {
+                bitmap = screenshot
+            }
+            tmp?.recycle()
+        }.onError {
+            AppLog.put("更新PageView图片出错", it)
         }
         }
     }
     }
 
 

+ 4 - 4
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) {
         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
         }
         }