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

This commit is contained in:
len 2016-12-10 14:49:56 +01:00
parent 26b283d44d
commit 7c42ab885b
6 changed files with 65 additions and 26 deletions

View file

@ -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) {

View file

@ -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.

View file

@ -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 {

View file

@ -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()
}

View file

@ -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)
}

View file

@ -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"