From 3bf7c74f9343542be74495d4cb48d1fe615839cb Mon Sep 17 00:00:00 2001 From: Andreas E Date: Sun, 3 Jan 2021 16:50:38 +0100 Subject: [PATCH] Navigation settings and split invert tapping for webtoon and pager (#4233) --- .../data/preference/PreferenceKeys.kt | 4 +- .../data/preference/PreferencesHelper.kt | 4 +- .../ui/reader/ReaderSettingsSheet.kt | 40 ++-- .../ui/reader/viewer/ViewerConfig.kt | 3 - .../ui/reader/viewer/pager/PagerConfig.kt | 3 + .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 3 + .../ui/setting/SettingsReaderController.kt | 90 ++++++-- .../main/res/layout/reader_pager_settings.xml | 124 ++++++++++ .../main/res/layout/reader_settings_sheet.xml | 211 ++---------------- .../res/layout/reader_webtoon_settings.xml | 106 +++++++++ 10 files changed, 345 insertions(+), 243 deletions(-) create mode 100644 app/src/main/res/layout/reader_pager_settings.xml create mode 100644 app/src/main/res/layout/reader_webtoon_settings.xml 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 33791194c..c2b93868b 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 @@ -57,7 +57,9 @@ object PreferenceKeys { const val readWithTapping = "reader_tap" - const val readWithTappingInverted = "reader_tapping_inverted" + const val pagerNavInverted = "reader_tapping_inverted" + + const val webtoonNavInverted = "reader_tapping_inverted_webtoon" const val readWithLongTap = "reader_long_tap" 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 ebad7166b..946078b0e 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 @@ -130,7 +130,9 @@ class PreferencesHelper(val context: Context) { fun readWithTapping() = flowPrefs.getBoolean(Keys.readWithTapping, true) - fun readWithTappingInverted() = flowPrefs.getEnum(Keys.readWithTappingInverted, Values.TappingInvertMode.NONE) + fun pagerNavInverted() = flowPrefs.getEnum(Keys.pagerNavInverted, Values.TappingInvertMode.NONE) + + fun webtoonNavInverted() = flowPrefs.getEnum(Keys.webtoonNavInverted, Values.TappingInvertMode.NONE) fun readWithLongTap() = flowPrefs.getBoolean(Keys.readWithLongTap, true) 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 5585aa16f..437381397 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 @@ -4,7 +4,7 @@ import android.os.Bundle import android.widget.CompoundButton import android.widget.Spinner import androidx.annotation.ArrayRes -import androidx.core.view.isInvisible +import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.core.widget.NestedScrollView import com.google.android.material.bottomsheet.BottomSheetDialog @@ -39,7 +39,6 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia super.onCreate(savedInstanceState) initGeneralPreferences() - initNavigationPreferences() when (activity.viewer) { is PagerViewer -> initPagerPreferences() @@ -83,36 +82,33 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia * Init the preferences for the pager reader. */ private fun initPagerPreferences() { - binding.webtoonPrefsGroup.isInvisible = true - binding.pagerPrefsGroup.isVisible = true + binding.webtoonPrefsGroup.root.isGone = true + binding.pagerPrefsGroup.root.isVisible = true - binding.pagerNav.bindToPreference(preferences.navigationModePager()) - binding.scaleType.bindToPreference(preferences.imageScaleType(), 1) - binding.zoomStart.bindToPreference(preferences.zoomStart(), 1) - binding.cropBorders.bindToPreference(preferences.cropBorders()) + binding.pagerPrefsGroup.tappingPrefsGroup.isVisible = preferences.readWithTapping().get() + + binding.pagerPrefsGroup.tappingInverted.bindToPreference(preferences.pagerNavInverted()) + + binding.pagerPrefsGroup.pagerNav.bindToPreference(preferences.navigationModePager()) + binding.pagerPrefsGroup.scaleType.bindToPreference(preferences.imageScaleType(), 1) + binding.pagerPrefsGroup.zoomStart.bindToPreference(preferences.zoomStart(), 1) + binding.pagerPrefsGroup.cropBorders.bindToPreference(preferences.cropBorders()) } /** * Init the preferences for the webtoon reader. */ private fun initWebtoonPreferences() { - binding.pagerPrefsGroup.isInvisible = true - binding.webtoonPrefsGroup.isVisible = true + binding.pagerPrefsGroup.root.isGone = true + binding.webtoonPrefsGroup.root.isVisible = true - binding.webtoonNav.bindToPreference(preferences.navigationModeWebtoon()) - binding.cropBordersWebtoon.bindToPreference(preferences.cropBordersWebtoon()) - binding.webtoonSidePadding.bindToIntPreference(preferences.webtoonSidePadding(), R.array.webtoon_side_padding_values) - } + binding.webtoonPrefsGroup.tappingPrefsGroup.isVisible = preferences.readWithTapping().get() - /** - * Init the preferences for navigation. - */ - private fun initNavigationPreferences() { - if (!preferences.readWithTapping().get()) { - binding.navigationPrefsGroup.isVisible = false - } + binding.webtoonPrefsGroup.tappingInverted.bindToPreference(preferences.webtoonNavInverted()) - binding.tappingInverted.bindToPreference(preferences.readWithTappingInverted()) + binding.webtoonPrefsGroup.webtoonNav.bindToPreference(preferences.navigationModeWebtoon()) + binding.webtoonPrefsGroup.cropBordersWebtoon.bindToPreference(preferences.cropBordersWebtoon()) + binding.webtoonPrefsGroup.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 9cee493a2..35354a9dc 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 @@ -38,9 +38,6 @@ abstract class ViewerConfig(preferences: PreferencesHelper) { preferences.readWithTapping() .register({ tappingEnabled = it }) - preferences.readWithTappingInverted() - .register({ tappingInverted = it }, { navigator.invertMode = it }) - preferences.readWithLongTap() .register({ longTapEnabled = it }) 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 0abf2cd2e..c2e5f1470 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 @@ -36,6 +36,9 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe preferences.navigationModePager() .register({ navigationMode = it }, { updateNavigation(navigationMode) }) + + preferences.pagerNavInverted() + .register({ tappingInverted = it }, { navigator.invertMode = it }) } private fun zoomTypeFromPreference(value: Int) { 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 94ae03c36..1a37b5668 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 @@ -29,6 +29,9 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) : ViewerConfi preferences.navigationModeWebtoon() .register({ navigationMode = it }, { updateNavigation(it) }) + + preferences.webtoonNavInverted() + .register({ tappingInverted = it }, { navigator.invertMode = it }) } override var navigator: ViewerNavigation = defaultNavigation() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index f4162958e..e49c57b51 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -137,6 +137,41 @@ class SettingsReaderController : SettingsController() { preferenceCategory { titleRes = R.string.pager_viewer + intListPreference { + key = Keys.navigationModePager + titleRes = R.string.pref_viewer_nav + entriesRes = arrayOf( + R.string.default_nav, + R.string.l_nav, + R.string.kindlish_nav, + R.string.edge_nav + ) + entryValues = arrayOf("0", "1", "2", "3") + defaultValue = "0" + summary = "%s" + + preferences.readWithTapping().asImmediateFlow { isVisible = it }.launchIn(scope) + } + listPreference { + key = Keys.pagerNavInverted + titleRes = R.string.pref_read_with_tapping_inverted + entriesRes = arrayOf( + R.string.tapping_inverted_none, + R.string.tapping_inverted_horizontal, + R.string.tapping_inverted_vertical, + R.string.tapping_inverted_both + ) + entryValues = arrayOf( + TappingInvertMode.NONE.name, + TappingInvertMode.HORIZONTAL.name, + TappingInvertMode.VERTICAL.name, + TappingInvertMode.BOTH.name + ) + defaultValue = TappingInvertMode.NONE.name + summary = "%s" + + preferences.readWithTapping().asImmediateFlow { isVisible = it }.launchIn(scope) + } intListPreference { key = Keys.imageScaleType titleRes = R.string.pref_image_scale_type @@ -175,6 +210,41 @@ class SettingsReaderController : SettingsController() { preferenceCategory { titleRes = R.string.webtoon_viewer + intListPreference { + key = Keys.navigationModeWebtoon + titleRes = R.string.pref_viewer_nav + entriesRes = arrayOf( + R.string.default_nav, + R.string.l_nav, + R.string.kindlish_nav, + R.string.edge_nav + ) + entryValues = arrayOf("0", "1", "2", "3") + defaultValue = "0" + summary = "%s" + + preferences.readWithTapping().asImmediateFlow { isVisible = it }.launchIn(scope) + } + listPreference { + key = Keys.webtoonNavInverted + titleRes = R.string.pref_read_with_tapping_inverted + entriesRes = arrayOf( + R.string.tapping_inverted_none, + R.string.tapping_inverted_horizontal, + R.string.tapping_inverted_vertical, + R.string.tapping_inverted_both + ) + entryValues = arrayOf( + TappingInvertMode.NONE.name, + TappingInvertMode.HORIZONTAL.name, + TappingInvertMode.VERTICAL.name, + TappingInvertMode.BOTH.name + ) + defaultValue = TappingInvertMode.NONE.name + summary = "%s" + + preferences.readWithTapping().asImmediateFlow { isVisible = it }.launchIn(scope) + } intListPreference { key = Keys.webtoonSidePadding titleRes = R.string.pref_webtoon_side_padding @@ -204,26 +274,6 @@ class SettingsReaderController : SettingsController() { titleRes = R.string.pref_read_with_tapping defaultValue = true } - listPreference { - key = Keys.readWithTappingInverted - titleRes = R.string.pref_read_with_tapping_inverted - entriesRes = arrayOf( - R.string.tapping_inverted_none, - R.string.tapping_inverted_horizontal, - R.string.tapping_inverted_vertical, - R.string.tapping_inverted_both - ) - entryValues = arrayOf( - TappingInvertMode.NONE.name, - TappingInvertMode.HORIZONTAL.name, - TappingInvertMode.VERTICAL.name, - TappingInvertMode.BOTH.name - ) - defaultValue = TappingInvertMode.NONE.name - summary = "%s" - - preferences.readWithTapping().asImmediateFlow { isVisible = it }.launchIn(scope) - } switchPreference { key = Keys.readWithLongTap titleRes = R.string.pref_read_with_long_tap diff --git a/app/src/main/res/layout/reader_pager_settings.xml b/app/src/main/res/layout/reader_pager_settings.xml new file mode 100644 index 000000000..c3df83e81 --- /dev/null +++ b/app/src/main/res/layout/reader_pager_settings.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/reader_settings_sheet.xml b/app/src/main/res/layout/reader_settings_sheet.xml index 0ea618c60..890db6bd1 100644 --- a/app/src/main/res/layout/reader_settings_sheet.xml +++ b/app/src/main/res/layout/reader_settings_sheet.xml @@ -18,10 +18,10 @@ android:alpha="0.5" android:scaleType="fitCenter" android:src="@drawable/ic_drag_pill_24dp" - android:tint="?attr/colorOnBackground" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" + app:tint="?attr/colorOnBackground" /> - - - - - - - - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@+id/always_show_chapter_transition" + tools:visibility="visible" /> - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/always_show_chapter_transition" /> - - - - - - diff --git a/app/src/main/res/layout/reader_webtoon_settings.xml b/app/src/main/res/layout/reader_webtoon_settings.xml new file mode 100644 index 000000000..e87084302 --- /dev/null +++ b/app/src/main/res/layout/reader_webtoon_settings.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file