From 3ce9a9ff97eb63dd916dff63f8aa33cbd3b4c715 Mon Sep 17 00:00:00 2001 From: Ken Swenson Date: Tue, 25 Apr 2023 18:06:49 -0400 Subject: [PATCH] Double tap zoom toggle (#9384) * Double tap zoom toggle Implements a toggle that allows users to disable double tap zoom including QuickScaling for webtoons. Partially resolves #4145 * Update i18n/src/main/res/values/strings.xml --------- Co-authored-by: arkon --- .../more/settings/screen/SettingsReaderScreen.kt | 5 +++++ .../tachiyomi/ui/reader/setting/ReaderPreferences.kt | 2 ++ .../ui/reader/setting/ReaderReadingModeSettings.kt | 2 ++ .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 11 +++++++++++ .../ui/reader/viewer/webtoon/WebtoonFrame.kt | 7 +++++++ .../ui/reader/viewer/webtoon/WebtoonRecyclerView.kt | 4 +++- .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 4 ++++ app/src/main/res/layout/reader_webtoon_settings.xml | 9 +++++++++ i18n/src/main/res/values/strings.xml | 1 + 9 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt index d9b357495..c55c0d715 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt @@ -317,6 +317,11 @@ object SettingsReaderScreen : SearchableSettings { subtitle = stringResource(R.string.split_tall_images_summary), enabled = !isReleaseBuildType, // TODO: Show in release build when the feature is stable ), + Preference.PreferenceItem.SwitchPreference( + pref = readerPreferences.webtoonDoubleTapZoomEnabled(), + title = stringResource(R.string.pref_double_tap_zoom), + enabled = true, + ), ), ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt index ca4ca7be5..b2b82ea97 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt @@ -34,6 +34,8 @@ class ReaderPreferences( // TODO: Enable in release build when the feature is stable fun longStripSplitWebtoon() = preferenceStore.getBoolean("pref_long_strip_split_webtoon", !isReleaseBuildType) + fun webtoonDoubleTapZoomEnabled() = preferenceStore.getBoolean("pref_enable_double_tap_zoom_webtoon", true) + fun imageScaleType() = preferenceStore.getInt("pref_image_scale_type_key", 1) fun zoomStart() = preferenceStore.getInt("pref_zoom_start_key", 1) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt index e14300286..a3b9a42f1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt @@ -140,5 +140,7 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr binding.webtoonPrefsGroup.longStripSplit.isVisible = !isReleaseBuildType binding.webtoonPrefsGroup.longStripSplit.bindToPreference(readerPreferences.longStripSplitWebtoon()) + + binding.webtoonPrefsGroup.doubleTapZoom.bindToPreference(readerPreferences.webtoonDoubleTapZoomEnabled()) } } 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 c168a6366..b2e0045b8 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,11 @@ class WebtoonConfig( var longStripSplitChangedListener: ((Boolean) -> Unit)? = null + var doubleTapZoom = true + private set + + var doubleTapZoomChangedListener: ((Boolean) -> Unit)? = null + val theme = readerPreferences.readerTheme().get() init { @@ -71,6 +76,12 @@ class WebtoonConfig( }, ) + readerPreferences.webtoonDoubleTapZoomEnabled() + .register( + { doubleTapZoom = it }, + { doubleTapZoomChangedListener?.invoke(it) }, + ) + readerPreferences.readerTheme().changes() .drop(1) .distinctUntilChanged() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonFrame.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonFrame.kt index 323cf0f63..43c981b25 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonFrame.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonFrame.kt @@ -25,6 +25,13 @@ class WebtoonFrame(context: Context) : FrameLayout(context) { */ private val flingDetector = GestureDetector(context, FlingListener()) + var doubleTapZoom = true + set(value) { + field = value + recycler?.doubleTapZoom = value + scaleDetector.isQuickScaleEnabled = value + } + /** * Recycler view added in this frame. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt index 7a3b96676..b6abc4834 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt @@ -37,6 +37,8 @@ class WebtoonRecyclerView @JvmOverloads constructor( private val listener = GestureListener() private val detector = Detector() + var doubleTapZoom = true + var tapListener: ((MotionEvent) -> Unit)? = null var longTapListener: ((MotionEvent) -> Boolean)? = null @@ -209,7 +211,7 @@ class WebtoonRecyclerView @JvmOverloads constructor( } fun onDoubleTapConfirmed(ev: MotionEvent) { - if (!isZooming) { + if (!isZooming && doubleTapZoom) { if (scaleX != DEFAULT_RATE) { zoom(currentScale, DEFAULT_RATE, x, 0f, y, 0f) } else { 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 037d64e31..dab54cec9 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 @@ -142,6 +142,10 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr ActivityCompat.recreate(activity) } + config.doubleTapZoomChangedListener = { + frame.doubleTapZoom = it + } + config.navigationModeChangedListener = { val showOnStart = config.navigationOverlayOnStart || config.forceNavigationOverlay activity.binding.navigationOverlay.setNavigation(config.navigator, showOnStart) diff --git a/app/src/main/res/layout/reader_webtoon_settings.xml b/app/src/main/res/layout/reader_webtoon_settings.xml index ff0ddb766..2d5bb7b01 100644 --- a/app/src/main/res/layout/reader_webtoon_settings.xml +++ b/app/src/main/res/layout/reader_webtoon_settings.xml @@ -75,6 +75,15 @@ android:text="@string/pref_long_strip_split" android:textColor="?android:attr/textColorSecondary" /> + + Rotate wide pages to fit Flip orientation of rotated wide pages Split tall images (BETA) + Double tap to zoom Show content in cutout area Animate page transitions Double tap animation speed