From 7c42ab885b041dbcf91c7c7f75d34954a2ee5244 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 10 Dec 2016 14:49:56 +0100 Subject: [PATCH] Readers know how to move to each side. Fix #566 --- .../tachiyomi/ui/reader/ReaderActivity.kt | 13 ++++++---- .../ui/reader/viewer/base/BaseReader.kt | 22 +++++++++++++---- .../ui/reader/viewer/pager/PagerReader.kt | 20 ++++++++-------- .../pager/horizontal/RightToLeftReader.kt | 24 +++++++++++++++++-- .../ui/reader/viewer/webtoon/WebtoonReader.kt | 8 +++---- app/src/main/res/layout/activity_reader.xml | 4 +++- 6 files changed, 65 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index ee01d9026..04f2fb9df 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -189,7 +189,7 @@ class ReaderActivity : BaseRxActivity() { 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() { 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() { 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) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.kt index 0fb8296ea..85cab7474 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.kt +++ b/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. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt index 18cf1501c..a23c2efcf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt +++ b/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 { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/horizontal/RightToLeftReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/horizontal/RightToLeftReader.kt index 7a0eeb2d6..7815bc66b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/horizontal/RightToLeftReader.kt +++ b/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() } - override fun onRightSideTap() { + /** + * Moves a page down. + */ + override fun moveDown() { + moveToNext() + } + + /** + * Moves a page up. + */ + override fun moveUp() { moveToPrevious() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt index 20e6a0a2b..7b6bca4a5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt +++ b/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) } diff --git a/app/src/main/res/layout/activity_reader.xml b/app/src/main/res/layout/activity_reader.xml index 0cbec3f42..8e7fa74ea 100644 --- a/app/src/main/res/layout/activity_reader.xml +++ b/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">