Allow disabling reader's zoom out (#302)

* 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
This commit is contained in:
Splintor 2024-02-24 21:40:06 +02:00 committed by GitHub
parent 21020e1797
commit c15f3f2fd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 44 additions and 4 deletions

View file

@ -341,7 +341,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),
),
),
)

View file

@ -197,6 +197,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

View file

@ -72,6 +72,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

View file

@ -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 },

View file

@ -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.
*/

View file

@ -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()
@ -166,7 +175,7 @@ class WebtoonRecyclerView @JvmOverloads constructor(
fun onScale(scaleFactor: Float) {
currentScale *= scaleFactor
currentScale = currentScale.coerceIn(
MIN_RATE,
minRate,
MAX_SCALE_RATE,
)
@ -193,8 +202,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)
}
}

View file

@ -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)

View file

@ -453,6 +453,7 @@
<string name="pref_high">High</string>
<string name="pref_low">Low</string>
<string name="pref_lowest">Lowest</string>
<string name="pref_webtoon_disable_zoom_out">Disable zoom out</string>
<!-- Downloads section -->
<string name="pref_category_delete_chapters">Delete chapters</string>