Эх сурвалжийг харах

Fix webtoon reader touch events. #561

len 8 жил өмнө
parent
commit
26b283d44d

+ 6 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt

@@ -22,7 +22,12 @@ class WebtoonAdapter(val fragment: WebtoonReader) : RecyclerView.Adapter<Webtoon
     /**
      * Touch listener for images in holders.
      */
-    val touchListener = View.OnTouchListener { v, ev -> fragment.gestureDetector.onTouchEvent(ev) }
+    val imageTouchListener = View.OnTouchListener { v, ev -> fragment.imageGestureDetector.onTouchEvent(ev) }
+
+    /**
+     * Touch listener for the other views.
+     */
+    val viewTouchListener = View.OnTouchListener { v, ev -> fragment.viewGestureDetector.onTouchEvent(ev) }
 
     /**
      * Returns the number of pages.

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt

@@ -63,7 +63,7 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter)
             setRegionDecoderClass(webtoonReader.regionDecoderClass)
             setBitmapDecoderClass(webtoonReader.bitmapDecoderClass)
             setVerticalScrollingParent(true)
-            setOnTouchListener(adapter.touchListener)
+            setOnTouchListener(adapter.imageTouchListener)
             setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() {
                 override fun onReady() {
                     onImageDecoded()
@@ -77,7 +77,7 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter)
 
         view.progress_container.minimumHeight = view.resources.displayMetrics.heightPixels * 2
 
-        view.setOnTouchListener(adapter.touchListener)
+        view.setOnTouchListener(adapter.viewTouchListener)
         view.retry_button.setOnTouchListener { v, event ->
             if (event.action == MotionEvent.ACTION_UP) {
                 readerActivity.presenter.retryPage(page)

+ 48 - 30
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt

@@ -55,9 +55,14 @@ class WebtoonReader : BaseReader() {
         private set
 
     /**
-     * Gesture detector for touch events.
+     * Gesture detector for image touch events.
      */
-    val gestureDetector by lazy { createGestureDetector() }
+    val imageGestureDetector by lazy { GestureDetector(context, ImageGestureListener()) }
+
+    /**
+     * Gesture detector for other views touch events.
+     */
+    val viewGestureDetector by lazy { GestureDetector(context, ViewGestureListener()) }
 
     /**
      * Subscriptions used while the view exists.
@@ -122,39 +127,52 @@ class WebtoonReader : BaseReader() {
     }
 
     /**
-     * Creates the gesture detector for the reader.
-     *
-     * @return a gesture detector.
+     * Gesture detector for Subsampling Scale Image View. [onDown] needs to be false or else
+     * double tap to zoom doesn't work.
      */
-    protected fun createGestureDetector(): GestureDetector {
-        return GestureDetector(context, object : SimpleOnGestureListener() {
-            override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
-                if (isAdded) {
-                    val positionX = e.x
-
-                    if (positionX < recycler.width * LEFT_REGION) {
-                        if (tappingEnabled) moveToPrevious()
-                    } else if (positionX > recycler.width * RIGHT_REGION) {
-                        if (tappingEnabled) moveToNext()
-                    } else {
-                        readerActivity.toggleMenu()
-                    }
+    inner open class ImageGestureListener : SimpleOnGestureListener() {
+
+        override fun onDown(e: MotionEvent): Boolean {
+            return false
+        }
+
+        override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
+            if (isAdded) {
+                val positionX = e.x
+
+                if (positionX < recycler.width * LEFT_REGION) {
+                    if (tappingEnabled) moveToPrevious()
+                } else if (positionX > recycler.width * RIGHT_REGION) {
+                    if (tappingEnabled) moveToNext()
+                } else {
+                    readerActivity.toggleMenu()
                 }
-                return true
             }
+            return true
+        }
 
-            override fun onLongPress(e: MotionEvent) {
-                if (isAdded) {
-                    val child = recycler.findChildViewUnder(e.rawX, e.rawY)
-                    val position = recycler.getChildAdapterPosition(child)
-                    val page = adapter.pages?.getOrNull(position)
-                    if (page != null)
-                        readerActivity.onLongPress(page)
-                    else
-                        context.toast(getString(R.string.unknown_error))
-                }
+        override fun onLongPress(e: MotionEvent) {
+            if (isAdded) {
+                val child = recycler.findChildViewUnder(e.rawX, e.rawY)
+                val position = recycler.getChildAdapterPosition(child)
+                val page = adapter.pages?.getOrNull(position)
+                if (page != null)
+                    readerActivity.onLongPress(page)
+                else
+                    context.toast(getString(R.string.unknown_error))
             }
-        })
+        }
+    }
+
+    /**
+     * Gesture detector for other views. [onDown] needs to be true here or it will incorrectly
+     * detect events.
+     */
+    inner class ViewGestureListener : ImageGestureListener() {
+
+        override fun onDown(e: MotionEvent): Boolean {
+            return true
+        }
     }
 
     /**