From 09966bad71643d1e1602bde56b32ddcc15d12d3a Mon Sep 17 00:00:00 2001 From: Secozzi Date: Thu, 6 Jun 2024 01:17:57 +0200 Subject: [PATCH] Allow disabling reader's zoom out * Allow disabling reader's zoom out (#62) * Renamed disable zoom out pref and string * Zoom to default rate if the scale is inferior * Fixed null value check and formatting * Fixed detekt Co-authored-by: Splintor <55398298+Splintorien@users.noreply.github.com> --- .../more/settings/screen/SettingsReaderScreen.kt | 5 ++++- .../reader/settings/ReadingModePage.kt | 4 ++++ .../ui/reader/setting/ReaderPreferences.kt | 2 ++ .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 11 +++++++++++ .../ui/reader/viewer/webtoon/WebtoonFrame.kt | 6 ++++++ .../reader/viewer/webtoon/WebtoonRecyclerView.kt | 15 ++++++++++++--- .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 4 ++++ i18n/src/commonMain/resources/MR/base/strings.xml | 1 + 8 files changed, 44 insertions(+), 4 deletions(-) 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 88c2083e1..8472fbf88 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 @@ -345,7 +345,10 @@ object SettingsReaderScreen : SearchableSettings { Preference.PreferenceItem.SwitchPreference( pref = readerPreferences.webtoonDoubleTapZoomEnabled(), title = stringResource(MR.strings.pref_double_tap_zoom), - enabled = true, + ), + Preference.PreferenceItem.SwitchPreference( + pref = readerPreferences.webtoonDisableZoomOut(), + title = stringResource(MR.strings.pref_webtoon_disable_zoom_out), ), ), ) diff --git a/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt b/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt index 43b074a12..5a675f08b 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt @@ -205,6 +205,10 @@ private fun ColumnScope.WebtoonViewerSettings(screenModel: ReaderSettingsScreenM label = stringResource(MR.strings.pref_double_tap_zoom), pref = screenModel.preferences.webtoonDoubleTapZoomEnabled(), ) + CheckboxItem( + label = stringResource(MR.strings.pref_webtoon_disable_zoom_out), + pref = screenModel.preferences.webtoonDisableZoomOut(), + ) } @Composable 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 4888f9442..1e6c61b68 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 @@ -83,6 +83,8 @@ class ReaderPreferences( fun skipDupe() = preferenceStore.getBoolean("skip_dupe", false) + fun webtoonDisableZoomOut() = preferenceStore.getBoolean("webtoon_disable_zoom_out", false) + // endregion // region Split two page spread 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 28ad91a51..f55478862 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,11 @@ class WebtoonConfig( var imageCropBorders = false private set + var zoomOutDisabled = false + private set + + var zoomPropertyChangedListener: ((Boolean) -> Unit)? = null + var sidePadding = 0 private set @@ -74,6 +79,12 @@ class WebtoonConfig( { imagePropertyChangedListener?.invoke() }, ) + readerPreferences.webtoonDisableZoomOut() + .register( + { zoomOutDisabled = it }, + { zoomPropertyChangedListener?.invoke(it) } + ) + readerPreferences.webtoonDoubleTapZoomEnabled() .register( { doubleTapZoom = it }, 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 572335b25..17aafc6fd 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 @@ -33,6 +33,12 @@ class WebtoonFrame(context: Context) : FrameLayout(context) { scaleDetector.isQuickScaleEnabled = value } + var zoomOutDisabled = false + set(value) { + field = value + recycler?.zoomOutDisabled = 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 5e973d124..f4703ce8a 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 @@ -33,6 +33,15 @@ class WebtoonRecyclerView @JvmOverloads constructor( private var firstVisibleItemPosition = 0 private var lastVisibleItemPosition = 0 private var currentScale = DEFAULT_RATE + var zoomOutDisabled = false + set(value) { + field = value + if (value && currentScale < DEFAULT_RATE) { + zoom(currentScale, DEFAULT_RATE, x, 0f, y, 0f) + } + } + private val minRate + get() = if (zoomOutDisabled) DEFAULT_RATE else MIN_RATE private val listener = GestureListener() private val detector = Detector() @@ -174,7 +183,7 @@ class WebtoonRecyclerView @JvmOverloads constructor( fun onScale(scaleFactor: Float) { currentScale *= scaleFactor currentScale = currentScale.coerceIn( - MIN_RATE, + minRate, MAX_SCALE_RATE, ) @@ -201,8 +210,8 @@ class WebtoonRecyclerView @JvmOverloads constructor( } fun onScaleEnd() { - if (scaleX < MIN_RATE) { - zoom(currentScale, MIN_RATE, x, 0f, y, 0f) + if (scaleX < minRate) { + zoom(currentScale, minRate, x, 0f, y, 0f) } } 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 6b01584b1..1542883f3 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 @@ -152,6 +152,10 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr frame.doubleTapZoom = it } + config.zoomPropertyChangedListener = { + frame.zoomOutDisabled = it + } + config.navigationModeChangedListener = { val showOnStart = config.navigationOverlayOnStart || config.forceNavigationOverlay activity.binding.navigationOverlay.setNavigation(config.navigator, showOnStart) diff --git a/i18n/src/commonMain/resources/MR/base/strings.xml b/i18n/src/commonMain/resources/MR/base/strings.xml index 2e364c06d..2c86a8a54 100644 --- a/i18n/src/commonMain/resources/MR/base/strings.xml +++ b/i18n/src/commonMain/resources/MR/base/strings.xml @@ -416,6 +416,7 @@ High Low Lowest + Disable zoom out Excluded categories No storage location set Invalid location: %s