Horis 3 лет назад
Родитель
Сommit
ab6f3635eb

+ 31 - 15
app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt

@@ -55,7 +55,6 @@ class ReadView(context: Context, attrs: AttributeSet) :
     val defaultAnimationSpeed = 300
     private var pressDown = false
     private var isMove = false
-    private var isPageMove = false
 
     //起始点
     var startX: Float = 0f
@@ -83,8 +82,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
     private var pressOnTextSelected = false
     private val initialTextPos = TextPos(0, 0, 0)
 
-    val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop }
+    private val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop }
     private var pageSlopSquare: Int = slopSquare
+    var pageSlopSquare2: Int = pageSlopSquare * pageSlopSquare
     private val tlRect = RectF()
     private val tcRect = RectF()
     private val trRect = RectF()
@@ -182,7 +182,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
         }
 
         //在多点触控时,事件不走ACTION_DOWN分支而产生的特殊事件处理
-        if (event.actionMasked == MotionEvent.ACTION_POINTER_DOWN || event.actionMasked == MotionEvent.ACTION_POINTER_UP){
+        if (event.actionMasked == MotionEvent.ACTION_POINTER_DOWN || event.actionMasked == MotionEvent.ACTION_POINTER_UP) {
             pageDelegate?.onTouch(event)
         }
         when (event.action) {
@@ -199,36 +199,34 @@ class ReadView(context: Context, attrs: AttributeSet) :
                 postDelayed(longPressRunnable, longPressTimeout)
                 pressDown = true
                 isMove = false
-                isPageMove = false
                 pageDelegate?.onTouch(event)
                 pageDelegate?.onDown()
-                setStartPoint(event.x, event.y)
+                setStartPoint(event.x, event.y, false)
             }
+
             MotionEvent.ACTION_MOVE -> {
+                val absX = abs(startX - event.x)
+                val absY = abs(startY - event.y)
                 if (!isMove) {
-                    isMove =
-                        abs(startX - event.x) > slopSquare || abs(startY - event.y) > slopSquare
-                }
-                if (!isPageMove) {
-                    isPageMove =
-                        abs(startX - event.x) > pageSlopSquare || abs(startY - event.y) > pageSlopSquare
+                    isMove = absX > slopSquare || absY > slopSquare
                 }
                 if (isMove) {
                     longPressed = false
                     removeCallbacks(longPressRunnable)
                     if (isTextSelected) {
                         selectText(event.x, event.y)
-                    } else if (isPageMove) {
+                    } else {
                         pageDelegate?.onTouch(event)
                     }
                 }
             }
+
             MotionEvent.ACTION_UP -> {
                 callBack.screenOffTimerStart()
                 removeCallbacks(longPressRunnable)
                 if (!pressDown) return true
                 pressDown = false
-                if (!isPageMove) {
+                if (!pageDelegate!!.isMoved && !isMove) {
                     if (!longPressed && !pressOnTextSelected) {
                         if (!curPage.onClick(startX, startY)) {
                             onSingleTapUp()
@@ -238,18 +236,19 @@ class ReadView(context: Context, attrs: AttributeSet) :
                 }
                 if (isTextSelected) {
                     callBack.showTextActionMenu()
-                } else if (isPageMove) {
+                } else if (pageDelegate!!.isMoved) {
                     pageDelegate?.onTouch(event)
                 }
                 pressOnTextSelected = false
             }
+
             MotionEvent.ACTION_CANCEL -> {
                 removeCallbacks(longPressRunnable)
                 if (!pressDown) return true
                 pressDown = false
                 if (isTextSelected) {
                     callBack.showTextActionMenu()
-                } else if (isPageMove) {
+                } else if (pageDelegate!!.isMoved) {
                     pageDelegate?.onTouch(event)
                 }
                 pressOnTextSelected = false
@@ -375,27 +374,35 @@ class ReadView(context: Context, attrs: AttributeSet) :
             mcRect.contains(startX, startY) -> if (!isAbortAnim) {
                 click(AppConfig.clickActionMC)
             }
+
             bcRect.contains(startX, startY) -> {
                 click(AppConfig.clickActionBC)
             }
+
             blRect.contains(startX, startY) -> {
                 click(AppConfig.clickActionBL)
             }
+
             brRect.contains(startX, startY) -> {
                 click(AppConfig.clickActionBR)
             }
+
             mlRect.contains(startX, startY) -> {
                 click(AppConfig.clickActionML)
             }
+
             mrRect.contains(startX, startY) -> {
                 click(AppConfig.clickActionMR)
             }
+
             tlRect.contains(startX, startY) -> {
                 click(AppConfig.clickActionTL)
             }
+
             tcRect.contains(startX, startY) -> {
                 click(AppConfig.clickActionTC)
             }
+
             trRect.contains(startX, startY) -> {
                 click(AppConfig.clickActionTR)
             }
@@ -411,6 +418,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
                 pageDelegate?.dismissSnackBar()
                 callBack.showActionMenu()
             }
+
             1 -> pageDelegate?.nextPageByAnim(defaultAnimationSpeed)
             2 -> pageDelegate?.prevPageByAnim(defaultAnimationSpeed)
             3 -> ReadBook.moveToNextChapter(true)
@@ -436,6 +444,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
                     curPage.selectStartMoveIndex(textPos)
                     curPage.selectEndMoveIndex(initialTextPos)
                 }
+
                 else -> {
                     curPage.selectStartMoveIndex(initialTextPos)
                     curPage.selectEndMoveIndex(textPos)
@@ -461,9 +470,11 @@ class ReadView(context: Context, attrs: AttributeSet) :
             PageDirection.PREV -> {
                 pageFactory.moveToPrev(true)
             }
+
             PageDirection.NEXT -> {
                 pageFactory.moveToNext(true)
             }
+
             else -> false
         }
     }
@@ -478,15 +489,19 @@ class ReadView(context: Context, attrs: AttributeSet) :
             PageAnim.coverPageAnim -> if (pageDelegate !is CoverPageDelegate) {
                 pageDelegate = CoverPageDelegate(this)
             }
+
             PageAnim.slidePageAnim -> if (pageDelegate !is SlidePageDelegate) {
                 pageDelegate = SlidePageDelegate(this)
             }
+
             PageAnim.simulationPageAnim -> if (pageDelegate !is SimulationPageDelegate) {
                 pageDelegate = SimulationPageDelegate(this)
             }
+
             PageAnim.scrollPageAnim -> if (pageDelegate !is ScrollPageDelegate) {
                 pageDelegate = ScrollPageDelegate(this)
             }
+
             else -> if (pageDelegate !is NoAnimPageDelegate) {
                 pageDelegate = NoAnimPageDelegate(this)
             }
@@ -524,6 +539,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
     fun upPageSlopSquare() {
         val pageTouchSlop = AppConfig.pageTouchSlop
         this.pageSlopSquare = if (pageTouchSlop == 0) slopSquare else pageTouchSlop
+        pageSlopSquare2 = this.pageSlopSquare * this.pageSlopSquare
     }
 
     /**

+ 2 - 1
app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt

@@ -13,7 +13,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
     protected var prevBitmap: Bitmap? = null
     protected var nextBitmap: Bitmap? = null
     protected var canvas: Canvas = Canvas()
-    private val slopSquare by lazy { readView.slopSquare * readView.slopSquare }
+    private val slopSquare get() = readView.pageSlopSquare2
 
     override fun setDirection(direction: PageDirection) {
         super.setDirection(direction)
@@ -91,6 +91,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
                     }
                     setDirection(PageDirection.NEXT)
                 }
+                readView.setStartPoint(event.x, event.y, false)
             }
         }
         if (isMoved) {

+ 8 - 2
app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt

@@ -17,6 +17,7 @@ class ScrollPageDelegate(readView: ReadView) : PageDelegate(readView) {
 
     //速度追踪器
     private val mVelocity: VelocityTracker = VelocityTracker.obtain()
+    private val slopSquare get() = readView.pageSlopSquare2
 
     var noAnim: Boolean = false
 
@@ -77,12 +78,17 @@ class ScrollPageDelegate(readView: ReadView) : PageDelegate(readView) {
         //多点触控时即最后按下的手指产生的事件点
         val pointX = event.getX(event.pointerCount - 1)
         val pointY = event.getY(event.pointerCount - 1)
-        readView.setTouchPoint(pointX, pointY)
+        if (isMoved) {
+            readView.setTouchPoint(pointX, pointY)
+        }
         if (!isMoved) {
             val deltaX = (pointX - startX).toInt()
             val deltaY = (pointY - startY).toInt()
             val distance = deltaX * deltaX + deltaY * deltaY
-            isMoved = distance > readView.slopSquare
+            isMoved = distance > slopSquare
+            if (isMoved) {
+                readView.setStartPoint(event.x, event.y, false)
+            }
         }
         if (isMoved) {
             isRunning = true