From 7a64bf55cb8255000da7aaa0030f845b94d985b0 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 28 Feb 2021 22:17:37 +0100 Subject: [PATCH] Dual page split allow to have different setting for Paged and Webtoon (#4527) --- .../data/preference/PreferenceKeys.kt | 8 +++-- .../data/preference/PreferencesHelper.kt | 8 +++-- .../ui/reader/ReaderSettingsSheet.kt | 21 +++++++---- .../ui/reader/viewer/ViewerConfig.kt | 14 ++++---- .../ui/reader/viewer/pager/PagerConfig.kt | 6 ++++ .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 6 ++++ .../ui/setting/SettingsReaderController.kt | 36 ++++++++++++------- 7 files changed, 68 insertions(+), 31 deletions(-) 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 684dc5c29..cb91777b2 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 @@ -23,9 +23,13 @@ object PreferenceKeys { const val showPageNumber = "pref_show_page_number_key" - const val dualPageSplit = "pref_dual_page_split" + const val dualPageSplitPaged = "pref_dual_page_split" - const val dualPageInvert = "pref_dual_page_invert" + const val dualPageSplitWebtoon = "pref_dual_page_split_webtoon" + + const val dualPageInvertPaged = "pref_dual_page_invert" + + const val dualPageInvertWebtoon = "pref_dual_page_invert_webtoon" const val showReadingMode = "pref_show_reading_mode" 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 7e75acca6..09b6ef143 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 @@ -89,9 +89,13 @@ class PreferencesHelper(val context: Context) { fun showPageNumber() = flowPrefs.getBoolean(Keys.showPageNumber, true) - fun dualPageSplit() = flowPrefs.getBoolean(Keys.dualPageSplit, false) + fun dualPageSplitPaged() = flowPrefs.getBoolean(Keys.dualPageSplitPaged, false) - fun dualPageInvert() = flowPrefs.getBoolean(Keys.dualPageInvert, false) + fun dualPageSplitWebtoon() = flowPrefs.getBoolean(Keys.dualPageSplitWebtoon, false) + + fun dualPageInvertPaged() = flowPrefs.getBoolean(Keys.dualPageInvertPaged, false) + + fun dualPageInvertWebtoon() = flowPrefs.getBoolean(Keys.dualPageInvertWebtoon, false) fun showReadingMode() = prefs.getBoolean(Keys.showReadingMode, 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 2ee7533f2..1cae74936 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 @@ -68,18 +68,11 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BaseBottomShee binding.backgroundColor.bindToIntPreference(preferences.readerTheme(), R.array.reader_themes_values) binding.showPageNumber.bindToPreference(preferences.showPageNumber()) binding.fullscreen.bindToPreference(preferences.fullscreen()) - binding.dualPageSplit.bindToPreference(preferences.dualPageSplit()) binding.keepscreen.bindToPreference(preferences.keepScreenOn()) binding.longTap.bindToPreference(preferences.readWithLongTap()) binding.alwaysShowChapterTransition.bindToPreference(preferences.alwaysShowChapterTransition()) binding.pageTransitions.bindToPreference(preferences.pageTransitions()) - // Makes so that dual page invert gets hidden away when turning of dual page split - preferences.dualPageSplit() - .asImmediateFlow { binding.dualPageInvert.isVisible = it } - .launchIn(activity.lifecycleScope) - binding.dualPageInvert.bindToPreference(preferences.dualPageInvert()) - // If the preference is explicitly disabled, that means the setting was configured since there is a cutout if (activity.hasCutout || !preferences.cutoutShort().get()) { binding.cutoutShort.isVisible = true @@ -102,6 +95,13 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BaseBottomShee binding.pagerPrefsGroup.scaleType.bindToPreference(preferences.imageScaleType(), 1) binding.pagerPrefsGroup.zoomStart.bindToPreference(preferences.zoomStart(), 1) binding.pagerPrefsGroup.cropBorders.bindToPreference(preferences.cropBorders()) + + // Makes so that dual page invert gets hidden away when turning of dual page split + binding.dualPageSplit.bindToPreference(preferences.dualPageSplitPaged()) + preferences.dualPageSplitPaged() + .asImmediateFlow { binding.dualPageInvert.isVisible = it } + .launchIn(activity.lifecycleScope) + binding.dualPageInvert.bindToPreference(preferences.dualPageInvertPaged()) } /** @@ -118,6 +118,13 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BaseBottomShee binding.webtoonPrefsGroup.webtoonNav.bindToPreference(preferences.navigationModeWebtoon()) binding.webtoonPrefsGroup.cropBordersWebtoon.bindToPreference(preferences.cropBordersWebtoon()) binding.webtoonPrefsGroup.webtoonSidePadding.bindToIntPreference(preferences.webtoonSidePadding(), R.array.webtoon_side_padding_values) + + // Makes so that dual page invert gets hidden away when turning of dual page split + binding.dualPageSplit.bindToPreference(preferences.dualPageSplitWebtoon()) + preferences.dualPageSplitWebtoon() + .asImmediateFlow { binding.dualPageInvert.isVisible = it } + .launchIn(activity.lifecycleScope) + binding.dualPageInvert.bindToPreference(preferences.dualPageInvertWebtoon()) } /** 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 6614f9c6f..95184c0cd 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 @@ -24,11 +24,15 @@ abstract class ViewerConfig(preferences: PreferencesHelper, private val scope: C var volumeKeysInverted = false var trueColor = false var alwaysShowChapterTransition = true - var dualPageSplit = false - var dualPageInvert = false var navigationMode = 0 protected set + var dualPageSplit = false + protected set + + var dualPageInvert = false + protected set + abstract var navigator: ViewerNavigation protected set @@ -56,12 +60,6 @@ abstract class ViewerConfig(preferences: PreferencesHelper, private val scope: C preferences.alwaysShowChapterTransition() .register({ alwaysShowChapterTransition = it }) - - preferences.dualPageSplit() - .register({ dualPageSplit = it }, { imagePropertyChangedListener?.invoke() }) - - preferences.dualPageInvert() - .register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() }) } protected abstract fun defaultNavigation(): ViewerNavigation 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 77b158865..1e134ba83 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 @@ -44,6 +44,12 @@ class PagerConfig( preferences.pagerNavInverted() .register({ tappingInverted = it }, { navigator.invertMode = it }) + + preferences.dualPageSplitPaged() + .register({ dualPageSplit = it }, { imagePropertyChangedListener?.invoke() }) + + preferences.dualPageInvertPaged() + .register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() }) } 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 44eeb6f56..f427cff4c 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 @@ -37,6 +37,12 @@ class WebtoonConfig( preferences.webtoonNavInverted() .register({ tappingInverted = it }, { navigator.invertMode = it }) + + preferences.dualPageSplitWebtoon() + .register({ dualPageSplit = it }, { imagePropertyChangedListener?.invoke() }) + + preferences.dualPageInvertWebtoon() + .register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() }) } 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 c0a6ea719..443375f10 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 @@ -50,18 +50,6 @@ class SettingsReaderController : SettingsController() { summaryRes = R.string.pref_show_reading_mode_summary defaultValue = true } - switchPreference { - key = Keys.dualPageSplit - titleRes = R.string.pref_dual_page_split - defaultValue = false - } - switchPreference { - key = Keys.dualPageInvert - titleRes = R.string.pref_dual_page_invert - summaryRes = R.string.pref_dual_page_invert_summary - defaultValue = false - preferences.dualPageSplit().asImmediateFlow { isVisible = it }.launchIn(viewScope) - } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { switchPreference { key = Keys.trueColor @@ -213,6 +201,18 @@ class SettingsReaderController : SettingsController() { titleRes = R.string.pref_crop_borders defaultValue = false } + switchPreference { + key = Keys.dualPageSplitPaged + titleRes = R.string.pref_dual_page_split + defaultValue = false + } + switchPreference { + key = Keys.dualPageInvertPaged + titleRes = R.string.pref_dual_page_invert + summaryRes = R.string.pref_dual_page_invert_summary + defaultValue = false + preferences.dualPageSplitPaged().asImmediateFlow { isVisible = it }.launchIn(viewScope) + } } preferenceCategory { @@ -268,6 +268,18 @@ class SettingsReaderController : SettingsController() { titleRes = R.string.pref_crop_borders defaultValue = false } + switchPreference { + key = Keys.dualPageSplitWebtoon + titleRes = R.string.pref_dual_page_split + defaultValue = false + } + switchPreference { + key = Keys.dualPageInvertWebtoon + titleRes = R.string.pref_dual_page_invert + summaryRes = R.string.pref_dual_page_invert_summary + defaultValue = false + preferences.dualPageSplitWebtoon().asImmediateFlow { isVisible = it }.launchIn(viewScope) + } } preferenceCategory {