From c9b1a425a73fda175a72951a2883daebad9555ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Chr=C3=A1steck=C3=BD?= Date: Sat, 21 Nov 2020 04:25:24 +0100 Subject: [PATCH] add support for S Pen actions (#4029) --- app/src/main/AndroidManifest.xml | 9 ++- .../tachiyomi/ui/reader/ReaderActivity.kt | 11 ++++ .../ui/reader/viewer/pager/PagerViewer.kt | 13 +++- app/src/main/res/values-cs/strings.xml | 2 + app/src/main/res/values/strings.xml | 4 ++ app/src/main/res/xml/s_pen_actions.xml | 60 +++++++++++++++++++ 6 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/xml/s_pen_actions.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0c5ee81cc4..daea68caa0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -60,7 +60,14 @@ + android:launchMode="singleTask"> + + + + + + 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 9a6687f8c2..1c291f3b08 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 @@ -261,6 +261,17 @@ class ReaderActivity : BaseRxActivity() super.onBackPressed() } + override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean { + if (keyCode == KeyEvent.KEYCODE_N) { + presenter.loadNextChapter() + return true + } else if (keyCode == KeyEvent.KEYCODE_P) { + presenter.loadPreviousChapter() + return true + } + return super.onKeyUp(keyCode, event) + } + /** * Dispatches a key event. If the viewer doesn't handle it, call the default implementation. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index 373401ac05..50285aa530 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt @@ -324,6 +324,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { */ override fun handleKeyEvent(event: KeyEvent): Boolean { val isUp = event.action == KeyEvent.ACTION_UP + val ctrlPressed = event.metaState.and(KeyEvent.META_CTRL_ON) > 0 when (event.keyCode) { KeyEvent.KEYCODE_VOLUME_DOWN -> { @@ -340,8 +341,16 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { if (!config.volumeKeysInverted) moveUp() else moveDown() } } - KeyEvent.KEYCODE_DPAD_RIGHT -> if (isUp) moveRight() - KeyEvent.KEYCODE_DPAD_LEFT -> if (isUp) moveLeft() + KeyEvent.KEYCODE_DPAD_RIGHT -> { + if (isUp) { + if (ctrlPressed) moveToNext() else moveRight() + } + } + KeyEvent.KEYCODE_DPAD_LEFT -> { + if (isUp) { + if (ctrlPressed) moveToPrevious() else moveLeft() + } + } KeyEvent.KEYCODE_DPAD_DOWN -> if (isUp) moveDown() KeyEvent.KEYCODE_DPAD_UP -> if (isUp) moveUp() KeyEvent.KEYCODE_PAGE_DOWN -> if (isUp) moveDown() diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index ee073c1fbb..d115d6d290 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -401,4 +401,6 @@ Více Menu Zdroje + Předchozí stránka + Následující stránka \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 796a1fa0ca..d0431d08da 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -719,4 +719,8 @@ Vertical Both + + Previous page + Next page + diff --git a/app/src/main/res/xml/s_pen_actions.xml b/app/src/main/res/xml/s_pen_actions.xml new file mode 100644 index 0000000000..d088628182 --- /dev/null +++ b/app/src/main/res/xml/s_pen_actions.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file