Browse Source

Readers know how to move to each side. Fix #566

len 8 years ago
parent
commit
7c42ab885b

+ 8 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt

@@ -189,7 +189,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
                 KeyEvent.KEYCODE_VOLUME_DOWN -> {
                     if (volumeKeysEnabled) {
                         if (event.action == KeyEvent.ACTION_UP) {
-                            viewer?.moveToNext()
+                            viewer?.moveDown()
                         }
                         return true
                     }
@@ -197,7 +197,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
                 KeyEvent.KEYCODE_VOLUME_UP -> {
                     if (volumeKeysEnabled) {
                         if (event.action == KeyEvent.ACTION_UP) {
-                            viewer?.moveToPrevious()
+                            viewer?.moveUp()
                         }
                         return true
                     }
@@ -210,12 +210,15 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
     override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
         if (!isFinishing) {
             when (keyCode) {
-                KeyEvent.KEYCODE_DPAD_RIGHT -> viewer?.moveToNext()
-                KeyEvent.KEYCODE_DPAD_LEFT -> viewer?.moveToPrevious()
+                KeyEvent.KEYCODE_DPAD_RIGHT -> viewer?.moveRight()
+                KeyEvent.KEYCODE_DPAD_LEFT -> viewer?.moveLeft()
+                KeyEvent.KEYCODE_DPAD_DOWN -> viewer?.moveDown()
+                KeyEvent.KEYCODE_DPAD_UP -> viewer?.moveUp()
                 KeyEvent.KEYCODE_MENU -> toggleMenu()
+                else -> return super.onKeyUp(keyCode, event)
             }
         }
-        return super.onKeyUp(keyCode, event)
+        return true
     }
 
     fun onChapterError(error: Throwable) {

+ 18 - 4
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.kt

@@ -189,14 +189,28 @@ abstract class BaseReader : BaseFragment() {
     abstract fun onChapterAppended(chapter: ReaderChapter)
 
     /**
-     * Moves pages forward. Implementations decide how to move (by a page, by some distance...).
+     * Moves pages to right. Implementations decide how to move (by a page, by some distance...).
      */
-    abstract fun moveToNext()
+    abstract fun moveRight()
 
     /**
-     * Moves pages backward. Implementations decide how to move (by a page, by some distance...).
+     * Moves pages to left. Implementations decide how to move (by a page, by some distance...).
      */
-    abstract fun moveToPrevious()
+    abstract fun moveLeft()
+
+    /**
+     * Moves pages down. Implementations decide how to move (by a page, by some distance...).
+     */
+    open fun moveDown() {
+        moveRight()
+    }
+
+    /**
+     * Moves pages up. Implementations decide how to move (by a page, by some distance...).
+     */
+    open fun moveUp() {
+        moveLeft()
+    }
 
     /**
      * Sets the active decoder class.

+ 10 - 10
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt

@@ -177,9 +177,9 @@ abstract class PagerReader : BaseReader() {
                     val positionX = e.x
 
                     if (positionX < pager.width * LEFT_REGION) {
-                        if (tappingEnabled) onLeftSideTap()
+                        if (tappingEnabled) moveLeft()
                     } else if (positionX > pager.width * RIGHT_REGION) {
-                        if (tappingEnabled) onRightSideTap()
+                        if (tappingEnabled) moveRight()
                     } else {
                         readerActivity.toggleMenu()
                     }
@@ -258,23 +258,23 @@ abstract class PagerReader : BaseReader() {
     }
 
     /**
-     * Called when the left side of the screen was clicked.
+     * Moves a page to the right.
      */
-    protected open fun onLeftSideTap() {
-        moveToPrevious()
+    override fun moveRight() {
+        moveToNext()
     }
 
     /**
-     * Called when the right side of the screen was clicked.
+     * Moves a page to the left.
      */
-    protected open fun onRightSideTap() {
-        moveToNext()
+    override fun moveLeft() {
+        moveToPrevious()
     }
 
     /**
      * Moves to the next page or requests the next chapter if it's the last one.
      */
-    override fun moveToNext() {
+    protected fun moveToNext() {
         if (pager.currentItem != pager.adapter.count - 1) {
             pager.setCurrentItem(pager.currentItem + 1, transitions)
         } else {
@@ -285,7 +285,7 @@ abstract class PagerReader : BaseReader() {
     /**
      * Moves to the previous page or requests the previous chapter if it's the first one.
      */
-    override fun moveToPrevious() {
+    protected fun moveToPrevious() {
         if (pager.currentItem != 0) {
             pager.setCurrentItem(pager.currentItem - 1, transitions)
         } else {

+ 22 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/horizontal/RightToLeftReader.kt

@@ -19,11 +19,31 @@ class RightToLeftReader : PagerReader() {
         }
     }
 
-    override fun onLeftSideTap() {
+    /**
+     * Moves a page to the right.
+     */
+    override fun moveRight() {
+        moveToPrevious()
+    }
+
+    /**
+     * Moves a page to the left.
+     */
+    override fun moveLeft() {
+        moveToNext()
+    }
+
+    /**
+     * Moves a page down.
+     */
+    override fun moveDown() {
         moveToNext()
     }
 
-    override fun onRightSideTap() {
+    /**
+     * Moves a page up.
+     */
+    override fun moveUp() {
         moveToPrevious()
     }
 

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

@@ -141,9 +141,9 @@ class WebtoonReader : BaseReader() {
                 val positionX = e.x
 
                 if (positionX < recycler.width * LEFT_REGION) {
-                    if (tappingEnabled) moveToPrevious()
+                    if (tappingEnabled) moveLeft()
                 } else if (positionX > recycler.width * RIGHT_REGION) {
-                    if (tappingEnabled) moveToNext()
+                    if (tappingEnabled) moveRight()
                 } else {
                     readerActivity.toggleMenu()
                 }
@@ -223,14 +223,14 @@ class WebtoonReader : BaseReader() {
     /**
      * Moves to the next page or requests the next chapter if it's the last one.
      */
-    override fun moveToNext() {
+    override fun moveRight() {
         recycler.smoothScrollBy(0, scrollDistance)
     }
 
     /**
      * Moves to the previous page or requests the previous chapter if it's the first one.
      */
-    override fun moveToPrevious() {
+    override fun moveLeft() {
         recycler.smoothScrollBy(0, -scrollDistance)
     }
 

+ 3 - 1
app/src/main/res/layout/activity_reader.xml

@@ -57,7 +57,9 @@
             android:layout_gravity="bottom"
             android:gravity="center"
             android:background="?colorPrimary"
-            android:orientation="horizontal">
+            android:orientation="horizontal"
+            android:focusable="false"
+            android:descendantFocusability="blocksDescendants">
 
             <ImageButton
                 android:id="@+id/left_chapter"