From d69e9034ab5b1b23250b2f529d957f60b9084865 Mon Sep 17 00:00:00 2001 From: Andreas E Date: Sat, 2 Jan 2021 00:41:20 +0100 Subject: [PATCH] Viewer navigation (#3869) * Viewer navigation Co-authored-by: Harsh Parekh * Match current reader behavior and add ability to invert it * A bit of clean up * Clean up inversion * Only create navigator when changed and change tap zone when invertTapping is changed * Clean up PagerConfig * Change how Viewer navigation works * Add Edge Navigation Co-authored-by: Harsh Parekh --- .../data/preference/PreferenceKeys.kt | 4 ++ .../data/preference/PreferenceValues.kt | 8 ++-- .../data/preference/PreferencesHelper.kt | 4 ++ .../ui/reader/ReaderSettingsSheet.kt | 2 + .../ui/reader/viewer/ViewerConfig.kt | 11 ++++- .../ui/reader/viewer/ViewerNavigation.kt | 43 +++++++++++++++++ .../viewer/navigation/EdgeNavigation.kt | 32 +++++++++++++ .../viewer/navigation/KindlishNavigation.kt | 28 +++++++++++ .../reader/viewer/navigation/LNavigation.kt | 36 ++++++++++++++ .../ui/reader/viewer/pager/PagerConfig.kt | 29 ++++++++++++ .../viewer/pager/PagerDefaultNavigation.kt | 31 ++++++++++++ .../ui/reader/viewer/pager/PagerViewer.kt | 37 ++++----------- .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 26 ++++++++++ .../webtoon/WebtoonDefaultNavigation.kt | 5 ++ .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 31 +++++------- .../tachiyomi/util/lang/RectFExtensions.kt | 15 ++++++ .../main/res/layout/reader_settings_sheet.xml | 47 +++++++++++++++++-- app/src/main/res/values/arrays.xml | 14 ++++++ app/src/main/res/values/strings.xml | 5 ++ 19 files changed, 350 insertions(+), 58 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerNavigation.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/EdgeNavigation.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/KindlishNavigation.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/LNavigation.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerDefaultNavigation.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonDefaultNavigation.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/lang/RectFExtensions.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 4e285d7460..33791194c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -65,6 +65,10 @@ object PreferenceKeys { const val readWithVolumeKeysInverted = "reader_volume_keys_inverted" + const val navigationModePager = "reader_navigation_mode_pager" + + const val navigationModeWebtoon = "reader_navigation_mode_webtoon" + const val webtoonSidePadding = "webtoon_side_padding" const val portraitColumns = "pref_library_columns_portrait_key" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index e60f7f508a..1588b5d336 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -31,10 +31,10 @@ object PreferenceValues { LIST, } - enum class TappingInvertMode { + enum class TappingInvertMode(val shouldInvertHorizontal: Boolean = false, val shouldInvertVertical: Boolean = false) { NONE, - HORIZONTAL, - VERTICAL, - BOTH + HORIZONTAL(shouldInvertHorizontal = true), + VERTICAL(shouldInvertVertical = true), + BOTH(shouldInvertHorizontal = true, shouldInvertVertical = true) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 168a2b8551..ebad7166bd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -138,6 +138,10 @@ class PreferencesHelper(val context: Context) { fun readWithVolumeKeysInverted() = flowPrefs.getBoolean(Keys.readWithVolumeKeysInverted, false) + fun navigationModePager() = flowPrefs.getInt(Keys.navigationModePager, 0) + + fun navigationModeWebtoon() = flowPrefs.getInt(Keys.navigationModeWebtoon, 0) + fun portraitColumns() = flowPrefs.getInt(Keys.portraitColumns, 0) fun landscapeColumns() = flowPrefs.getInt(Keys.landscapeColumns, 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt index e3ef93a445..5585aa16ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt @@ -86,6 +86,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia binding.webtoonPrefsGroup.isInvisible = true binding.pagerPrefsGroup.isVisible = true + binding.pagerNav.bindToPreference(preferences.navigationModePager()) binding.scaleType.bindToPreference(preferences.imageScaleType(), 1) binding.zoomStart.bindToPreference(preferences.zoomStart(), 1) binding.cropBorders.bindToPreference(preferences.cropBorders()) @@ -98,6 +99,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia binding.pagerPrefsGroup.isInvisible = true binding.webtoonPrefsGroup.isVisible = true + binding.webtoonNav.bindToPreference(preferences.navigationModeWebtoon()) binding.cropBordersWebtoon.bindToPreference(preferences.cropBordersWebtoon()) binding.webtoonSidePadding.bindToIntPreference(preferences.webtoonSidePadding(), R.array.webtoon_side_padding_values) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt index 1f076f6e92..9cee493a20 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt @@ -28,13 +28,18 @@ abstract class ViewerConfig(preferences: PreferencesHelper) { var volumeKeysInverted = false var trueColor = false var alwaysShowChapterTransition = true + var navigationMode = 0 + protected set + + abstract var navigator: ViewerNavigation + protected set init { preferences.readWithTapping() .register({ tappingEnabled = it }) preferences.readWithTappingInverted() - .register({ tappingInverted = it }) + .register({ tappingInverted = it }, { navigator.invertMode = it }) preferences.readWithLongTap() .register({ longTapEnabled = it }) @@ -58,6 +63,10 @@ abstract class ViewerConfig(preferences: PreferencesHelper) { .register({ alwaysShowChapterTransition = it }) } + protected abstract fun defaultNavigation(): ViewerNavigation + + abstract fun updateNavigation(navigationMode: Int) + fun Preference.register( valueAssignment: (T) -> Unit, onChanged: (T) -> Unit = {} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerNavigation.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerNavigation.kt new file mode 100644 index 0000000000..ab2714dc32 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerNavigation.kt @@ -0,0 +1,43 @@ +package eu.kanade.tachiyomi.ui.reader.viewer + +import android.graphics.PointF +import android.graphics.RectF +import eu.kanade.tachiyomi.data.preference.PreferenceValues +import eu.kanade.tachiyomi.util.lang.invert + +abstract class ViewerNavigation { + + enum class NavigationRegion { + NEXT, PREV, MENU + } + + data class Region( + val rectF: RectF, + val type: NavigationRegion + ) { + fun invert(invertMode: PreferenceValues.TappingInvertMode): Region { + if (invertMode == PreferenceValues.TappingInvertMode.NONE) return this + return this.copy( + rectF = this.rectF.invert(invertMode) + ) + } + } + + private var constantMenuRegion: RectF = RectF(0f, 0f, 1f, 0.05f) + + abstract var regions: List + + var invertMode: PreferenceValues.TappingInvertMode = PreferenceValues.TappingInvertMode.NONE + + fun getAction(pos: PointF): NavigationRegion { + val x = pos.x + val y = pos.y + val region = regions.map { it.invert(invertMode) } + .find { it.rectF.contains(x, y) } + return when { + region != null -> region.type + constantMenuRegion.contains(x, y) -> NavigationRegion.MENU + else -> NavigationRegion.MENU + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/EdgeNavigation.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/EdgeNavigation.kt new file mode 100644 index 0000000000..c06c703a34 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/EdgeNavigation.kt @@ -0,0 +1,32 @@ +package eu.kanade.tachiyomi.ui.reader.viewer.navigation + +import android.graphics.RectF +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation + +/** + * Visualization of default state without any inversion + * +---+---+---+ + * | N | N | N | P: Previous + * +---+---+---+ + * | N | M | N | M: Menu + * +---+---+---+ + * | N | P | N | N: Next + * +---+---+---+ +*/ +class EdgeNavigation : ViewerNavigation() { + + override var regions: List = listOf( + Region( + rectF = RectF(0f, 0f, 0.33f, 1f), + type = NavigationRegion.NEXT + ), + Region( + rectF = RectF(0.33f, 0.66f, 0.66f, 1f), + type = NavigationRegion.PREV + ), + Region( + rectF = RectF(0.66f, 0f, 1f, 1f), + type = NavigationRegion.NEXT + ), + ) +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/KindlishNavigation.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/KindlishNavigation.kt new file mode 100644 index 0000000000..43c081f870 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/KindlishNavigation.kt @@ -0,0 +1,28 @@ +package eu.kanade.tachiyomi.ui.reader.viewer.navigation + +import android.graphics.RectF +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation + +/** + * Visualization of default state without any inversion + * +---+---+---+ + * | M | M | M | P: Previous + * +---+---+---+ + * | P | N | N | M: Menu + * +---+---+---+ + * | P | N | N | N: Next + * +---+---+---+ +*/ +class KindlishNavigation : ViewerNavigation() { + + override var regions: List = listOf( + Region( + rectF = RectF(0.33f, 0.33f, 1f, 1f), + type = NavigationRegion.NEXT + ), + Region( + rectF = RectF(0f, 0.33f, 0.33f, 1f), + type = NavigationRegion.PREV + ) + ) +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/LNavigation.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/LNavigation.kt new file mode 100644 index 0000000000..f5e42e3810 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/navigation/LNavigation.kt @@ -0,0 +1,36 @@ +package eu.kanade.tachiyomi.ui.reader.viewer.navigation + +import android.graphics.RectF +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation + +/** + * Visualization of default state without any inversion + * +---+---+---+ + * | N | N | N | P: Previous + * +---+---+---+ + * | N | M | P | M: Menu + * +---+---+---+ + * | P | P | P | N: Next + * +---+---+---+ + */ +open class LNavigation : ViewerNavigation() { + + override var regions: List = listOf( + Region( + rectF = RectF(0f, 0.33f, 0.33f, 0.66f), + type = NavigationRegion.NEXT + ), + Region( + rectF = RectF(0f, 0f, 1f, 0.33f), + type = NavigationRegion.NEXT + ), + Region( + rectF = RectF(0.66f, 0.33f, 1f, 0.66f), + type = NavigationRegion.PREV + ), + Region( + rectF = RectF(0f, 0.66f, 1f, 1f), + type = NavigationRegion.PREV + ) + ) +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt index e4dee7643c..0abf2cd2e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt @@ -2,6 +2,10 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation +import eu.kanade.tachiyomi.ui.reader.viewer.navigation.EdgeNavigation +import eu.kanade.tachiyomi.ui.reader.viewer.navigation.KindlishNavigation +import eu.kanade.tachiyomi.ui.reader.viewer.navigation.LNavigation import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -29,6 +33,9 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe preferences.cropBorders() .register({ imageCropBorders = it }, { imagePropertyChangedListener?.invoke() }) + + preferences.navigationModePager() + .register({ navigationMode = it }, { updateNavigation(navigationMode) }) } private fun zoomTypeFromPreference(value: Int) { @@ -48,6 +55,28 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe } } + override var navigator: ViewerNavigation = defaultNavigation() + set(value) { + field = value.also { it.invertMode = this.tappingInverted } + } + + override fun defaultNavigation(): ViewerNavigation { + return when (viewer) { + is VerticalPagerViewer -> VerticalPagerDefaultNavigation() + else -> PagerDefaultNavigation() + } + } + + override fun updateNavigation(navigationMode: Int) { + navigator = when (navigationMode) { + 0 -> defaultNavigation() + 1 -> LNavigation() + 2 -> KindlishNavigation() + 3 -> EdgeNavigation() + else -> defaultNavigation() + } + } + enum class ZoomType { Left, Center, Right } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerDefaultNavigation.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerDefaultNavigation.kt new file mode 100644 index 0000000000..95bbd40d0b --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerDefaultNavigation.kt @@ -0,0 +1,31 @@ +package eu.kanade.tachiyomi.ui.reader.viewer.pager + +import android.graphics.RectF +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation +import eu.kanade.tachiyomi.ui.reader.viewer.navigation.LNavigation + +/** + * Visualization of default state without any inversion + * +---+---+---+ + * | N | M | P | P: Previous + * +---+---+---+ + * | N | M | P | M: Menu + * +---+---+---+ + * | N | M | P | N: Next + * +---+---+---+ + */ +class PagerDefaultNavigation : ViewerNavigation() { + + override var regions: List = listOf( + Region( + rectF = RectF(0f, 0f, 0.33f, 1f), + type = NavigationRegion.NEXT + ), + Region( + rectF = RectF(0.66f, 0f, 1f, 1f), + type = NavigationRegion.PREV + ), + ) +} + +class VerticalPagerDefaultNavigation : LNavigation() 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 d485c7a71f..3607e4fa6d 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 @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager +import android.graphics.PointF import android.view.InputDevice import android.view.KeyEvent import android.view.MotionEvent @@ -9,12 +10,12 @@ import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.viewpager.widget.ViewPager import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferenceValues.TappingInvertMode import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation import timber.log.Timber import kotlin.math.min @@ -89,34 +90,12 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { return@f } - val positionX = event.x - val positionY = event.y - val topSideTap = positionY < pager.height * 0.25f - val bottomSideTap = positionY > pager.height * 0.75f - val leftSideTap = positionX < pager.width * 0.33f - val rightSideTap = positionX > pager.width * 0.66f - - val invertMode = config.tappingInverted - val invertVertical = invertMode == TappingInvertMode.VERTICAL || invertMode == TappingInvertMode.BOTH - val invertHorizontal = invertMode == TappingInvertMode.HORIZONTAL || invertMode == TappingInvertMode.BOTH - - if (this is VerticalPagerViewer) { - when { - topSideTap && !invertVertical || bottomSideTap && invertVertical -> moveLeft() - bottomSideTap && !invertVertical || topSideTap && invertVertical -> moveRight() - - leftSideTap && !invertHorizontal || rightSideTap && invertHorizontal -> moveLeft() - rightSideTap && !invertHorizontal || leftSideTap && invertHorizontal -> moveRight() - - else -> activity.toggleMenu() - } - } else { - when { - leftSideTap && !invertHorizontal || rightSideTap && invertHorizontal -> moveLeft() - rightSideTap && !invertHorizontal || leftSideTap && invertHorizontal -> moveRight() - - else -> activity.toggleMenu() - } + val pos = PointF(event.rawX / pager.width, event.rawY / pager.height) + val navigator = config.navigator + when (navigator.getAction(pos)) { + ViewerNavigation.NavigationRegion.MENU -> activity.toggleMenu() + ViewerNavigation.NavigationRegion.NEXT -> moveToNext() + ViewerNavigation.NavigationRegion.PREV -> moveToPrevious() } } pager.longTapListener = f@{ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt index 6f108b892c..94ae03c36d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt @@ -2,6 +2,10 @@ package eu.kanade.tachiyomi.ui.reader.viewer.webtoon import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation +import eu.kanade.tachiyomi.ui.reader.viewer.navigation.EdgeNavigation +import eu.kanade.tachiyomi.ui.reader.viewer.navigation.KindlishNavigation +import eu.kanade.tachiyomi.ui.reader.viewer.navigation.LNavigation import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -22,5 +26,27 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) : ViewerConfi preferences.webtoonSidePadding() .register({ sidePadding = it }, { imagePropertyChangedListener?.invoke() }) + + preferences.navigationModeWebtoon() + .register({ navigationMode = it }, { updateNavigation(it) }) + } + + override var navigator: ViewerNavigation = defaultNavigation() + set(value) { + field = value.also { it.invertMode = tappingInverted } + } + + override fun defaultNavigation(): ViewerNavigation { + return WebtoonDefaultNavigation() + } + + override fun updateNavigation(navigationMode: Int) { + this.navigator = when (navigationMode) { + 0 -> defaultNavigation() + 1 -> LNavigation() + 2 -> KindlishNavigation() + 3 -> EdgeNavigation() + else -> defaultNavigation() + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonDefaultNavigation.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonDefaultNavigation.kt new file mode 100644 index 0000000000..04e05909dc --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonDefaultNavigation.kt @@ -0,0 +1,5 @@ +package eu.kanade.tachiyomi.ui.reader.viewer.webtoon + +import eu.kanade.tachiyomi.ui.reader.viewer.navigation.LNavigation + +class WebtoonDefaultNavigation : LNavigation() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 4364d5a88b..a78ef9db92 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.reader.viewer.webtoon +import android.graphics.PointF import android.view.KeyEvent import android.view.MotionEvent import android.view.View @@ -9,12 +10,12 @@ import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.WebtoonLayoutManager -import eu.kanade.tachiyomi.data.preference.PreferenceValues.TappingInvertMode import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation import rx.subscriptions.CompositeSubscription import timber.log.Timber import kotlin.math.max @@ -101,25 +102,15 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr return@f } - val positionX = event.rawX - val positionY = event.rawY - val topSideTap = positionY < recycler.height * 0.25f - val bottomSideTap = positionY > recycler.height * 0.75f - val leftSideTap = positionX < recycler.width * 0.33f - val rightSideTap = positionX > recycler.width * 0.66f - - val invertMode = config.tappingInverted - val invertVertical = invertMode == TappingInvertMode.VERTICAL || invertMode == TappingInvertMode.BOTH - val invertHorizontal = invertMode == TappingInvertMode.HORIZONTAL || invertMode == TappingInvertMode.BOTH - - when { - topSideTap && !invertVertical || bottomSideTap && invertVertical -> scrollUp() - bottomSideTap && !invertVertical || topSideTap && invertVertical -> scrollDown() - - leftSideTap && !invertHorizontal || rightSideTap && invertHorizontal -> scrollUp() - rightSideTap && !invertHorizontal || leftSideTap && invertHorizontal -> scrollDown() - - else -> activity.toggleMenu() + val pos = PointF(event.rawX / recycler.width, event.rawY / recycler.height) + if (!config.tappingEnabled) activity.toggleMenu() + else { + val navigator = config.navigator + when (navigator.getAction(pos)) { + ViewerNavigation.NavigationRegion.MENU -> activity.toggleMenu() + ViewerNavigation.NavigationRegion.NEXT -> scrollDown() + ViewerNavigation.NavigationRegion.PREV -> scrollUp() + } } } recycler.longTapListener = f@{ event -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/RectFExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/RectFExtensions.kt new file mode 100644 index 0000000000..d1ad0b5b9a --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/RectFExtensions.kt @@ -0,0 +1,15 @@ +package eu.kanade.tachiyomi.util.lang + +import android.graphics.RectF +import eu.kanade.tachiyomi.data.preference.PreferenceValues + +fun RectF.invert(invertMode: PreferenceValues.TappingInvertMode): RectF { + val horizontal = invertMode.shouldInvertHorizontal + val vertical = invertMode.shouldInvertVertical + return when { + horizontal && vertical -> RectF(1f - this.right, 1f - this.bottom, 1f - this.left, 1f - this.top) + vertical -> RectF(this.left, 1f - this.bottom, this.right, 1f - this.top) + horizontal -> RectF(1f - this.right, this.top, 1f - this.left, this.bottom) + else -> this + } +} diff --git a/app/src/main/res/layout/reader_settings_sheet.xml b/app/src/main/res/layout/reader_settings_sheet.xml index 8e8c056217..0ea618c608 100644 --- a/app/src/main/res/layout/reader_settings_sheet.xml +++ b/app/src/main/res/layout/reader_settings_sheet.xml @@ -203,6 +203,25 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/end_navigation_preferences" /> + + + + + app:layout_constraintTop_toBottomOf="@+id/pager_nav" /> + + + + + app:layout_constraintTop_toBottomOf="@+id/webtoon_nav" /> @@ -342,7 +381,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" - app:constraint_referenced_ids="pager_prefs,scale_type_text,scale_type,zoom_start_text,zoom_start,crop_borders" + app:constraint_referenced_ids="pager_prefs,pager_nav_text,pager_nav,scale_type_text,scale_type,zoom_start_text,zoom_start,crop_borders" tools:visibility="visible" /> + app:constraint_referenced_ids="webtoon_prefs,webtoon_nav_text,webtoon_nav,crop_borders_webtoon,webtoon_side_padding_text,webtoon_side_padding" /> @string/manga_from_library @string/downloaded_chapters + + + @string/default_nav + @string/l_nav + @string/kindlish_nav + @string/edge_nav + + + + @string/default_nav + @string/l_nav + @string/kindlish_nav + @string/edge_nav + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d60a9143c1..21d601f33a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -277,12 +277,17 @@ Black Default reading mode Default + Default + L shaped + Kindle-ish + Edge Left to right Right to left Vertical Webtoon Continuous vertical Paged + Navigation layout Image decoder Scale type Fit screen