From 1d1e5f1f995b5f9757481da35bf5d3241db8d1fc Mon Sep 17 00:00:00 2001 From: len Date: Sun, 1 May 2016 21:53:00 +0200 Subject: [PATCH] Toggle reader menu with the menu button, closes #286. Fix incorrect drawer selected item when using back button --- .../kanade/tachiyomi/ui/main/MainActivity.kt | 3 ++- .../tachiyomi/ui/reader/ReaderActivity.kt | 23 ++++++++++--------- .../ui/reader/viewer/pager/PagerReader.kt | 2 +- .../ui/reader/viewer/webtoon/WebtoonReader.kt | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index ace323f7a..eea2358b2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -76,7 +76,8 @@ class MainActivity : BaseActivity() { override fun onBackPressed() { supportFragmentManager.findFragmentById(R.id.frame_container)?.let { if (it !is LibraryFragment) { - setFragment(LibraryFragment.newInstance()) + nav_view.setCheckedItem(R.id.nav_drawer_library) + nav_view.menu.performIdentifierAction(R.id.nav_drawer_library, 0) } else { super.onBackPressed() } 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 86ee4d628..ca8571d70 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 @@ -201,21 +201,22 @@ class ReaderActivity : BaseRxActivity() { return true } } - KeyEvent.KEYCODE_DPAD_RIGHT -> { - if (event.action == KeyEvent.ACTION_UP) { - viewer?.moveToNext() - } - } - KeyEvent.KEYCODE_DPAD_LEFT -> { - if (event.action == KeyEvent.ACTION_UP) { - viewer?.moveToPrevious() - } - } } } return super.dispatchKeyEvent(event) } + 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_MENU -> toggleMenu() + } + } + return super.onKeyUp(keyCode, event) + } + fun onChapterError(error: Throwable) { Timber.e(error, error.message) finish() @@ -318,7 +319,7 @@ class ReaderActivity : BaseRxActivity() { } } - fun onCenterSingleTap() { + fun toggleMenu() { setMenuVisibility(reader_menu.visibility == View.GONE) } 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 5ac17fc44..f49126cc1 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 @@ -168,7 +168,7 @@ abstract class PagerReader : BaseReader() { } else if (positionX > pager.width * RIGHT_REGION) { if (tappingEnabled) onRightSideTap() } else { - readerActivity.onCenterSingleTap() + readerActivity.toggleMenu() } return true } 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 e37dd97f6..e93f696cf 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 @@ -130,7 +130,7 @@ class WebtoonReader : BaseReader() { } else if (positionX > recycler.width * RIGHT_REGION) { if (tappingEnabled) moveToNext() } else { - readerActivity.onCenterSingleTap() + readerActivity.toggleMenu() } return true }