Horis 2 лет назад
Родитель
Сommit
7e8e65dcbd

+ 16 - 4
app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt

@@ -172,11 +172,23 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
 
     private fun preRenderPage() {
         val view = this
+        var invalidate = false
         pageFactory.run {
-            prevPage.preRender(view)
-            curPage.preRender(view)
-            nextPage.preRender(view)
-            nextPlusPage.preRender(view)
+            hasPrev() && prevPage.preRender(view)
+            if (curPage.preRender(view)) {
+                invalidate = true
+            }
+            if (hasNext() && nextPage.preRender(view) && callBack.isScroll) {
+                invalidate = true
+            }
+            if (hasNextPlus() && nextPlusPage.preRender(view) && callBack.isScroll
+                && relativeOffset(2) < ChapterProvider.visibleHeight
+            ) {
+                invalidate = true
+            }
+            if (invalidate) {
+                postInvalidate()
+            }
         }
     }
 

+ 4 - 3
app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt

@@ -264,7 +264,7 @@ data class TextPage(
     }
 
     fun draw(view: ContentTextView, canvas: Canvas?) {
-        pictureMirror.drawLocked(canvas, view.width, height.toInt(), view) {
+        pictureMirror.drawLocked(canvas, view.width, height.toInt()) {
             drawPage(view, this)
         }
     }
@@ -278,9 +278,10 @@ data class TextPage(
         }
     }
 
-    fun preRender(view: ContentTextView) {
-        if (!pictureMirror.isDirty) return
+    fun preRender(view: ContentTextView): Boolean {
+        if (!pictureMirror.isDirty) return false
         draw(view, null)
+        return true
     }
 
     fun isDirty(): Boolean {

+ 2 - 12
app/src/main/java/io/legado/app/utils/PictureMirror.kt

@@ -3,41 +3,31 @@ package io.legado.app.utils
 import android.graphics.Canvas
 import android.graphics.Picture
 import android.os.Build
-import android.view.View
 import androidx.core.graphics.record
 import java.util.concurrent.locks.ReentrantLock
 
 class PictureMirror {
 
     var picture: Picture? = null
+
     @Volatile
     var isDirty = true
     val lock = ReentrantLock()
-    @Volatile
-    var scheduleInvalidateView: View? = null
 
     inline fun drawLocked(
         canvas: Canvas?,
         width: Int,
         height: Int,
-        view: View? = null,
         block: Canvas.() -> Unit
     ) {
         if (atLeastApi23) {
             if (picture == null) picture = Picture()
             val picture = picture!!
             if (isDirty) {
-                if (!lock.tryLock()) {
-                    if (canvas != null && view != null) {
-                        scheduleInvalidateView = view
-                    }
-                    return
-                }
+                if (!lock.tryLock()) return
                 try {
                     picture.record(width, height, block)
                     isDirty = false
-                    scheduleInvalidateView?.postInvalidate()
-                    scheduleInvalidateView = null
                 } finally {
                     lock.unlock()
                 }