From 2f0133986a60fbd4218e32fce19df6171bad4e71 Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 11 Jul 2023 22:24:16 -0400 Subject: [PATCH] Move boolean reading mode prefs to Compose sheet Also allow webtoon side padding to be any amount between 0 - 25%. --- .../more/settings/PreferenceItem.kt | 2 +- .../settings/screen/SettingsReaderScreen.kt | 21 +-- .../reader/settings/GeneralSettingsPage.kt | 2 +- .../reader/settings/ReadingModePage.kt | 167 +++++++++++++++++- .../ui/reader/setting/ReaderPreferences.kt | 7 +- .../ui/reader/setting/ReaderSettingsSheet.kt | 46 ----- .../tachiyomi/widget/MaterialSpinnerView.kt | 12 -- .../main/res/layout/reader_pager_settings.xml | 74 -------- .../layout/reader_reading_mode_settings.xml | 2 - .../res/layout/reader_webtoon_settings.xml | 61 ------- app/src/main/res/values/arrays.xml | 18 -- i18n/src/main/res/values/strings.xml | 8 +- 12 files changed, 187 insertions(+), 233 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceItem.kt b/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceItem.kt index 0625cc3e7a..fc383e2f55 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceItem.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceItem.kt @@ -87,7 +87,7 @@ internal fun PreferenceItem( min = item.min, max = item.max, value = item.value, - valueText = item.value.toString(), + valueText = item.subtitle.takeUnless { it.isNullOrEmpty() } ?: item.value.toString(), onChange = { scope.launch { item.onValueChanged(it) 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 f069708654..05ffec8f89 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 @@ -250,9 +250,11 @@ object SettingsReaderScreen : SearchableSettings { private fun getWebtoonGroup(readerPreferences: ReaderPreferences): Preference.PreferenceGroup { val navModePref = readerPreferences.navigationModeWebtoon() val dualPageSplitPref = readerPreferences.dualPageSplitWebtoon() + val webtoonSidePaddingPref = readerPreferences.webtoonSidePadding() val navMode by navModePref.collectAsState() val dualPageSplit by dualPageSplitPref.collectAsState() + val webtoonSidePadding by webtoonSidePaddingPref.collectAsState() return Preference.PreferenceGroup( title = stringResource(R.string.webtoon_viewer), @@ -275,17 +277,16 @@ object SettingsReaderScreen : SearchableSettings { ), enabled = navMode != 5, ), - Preference.PreferenceItem.ListPreference( - pref = readerPreferences.webtoonSidePadding(), + Preference.PreferenceItem.SliderPreference( + value = webtoonSidePadding, title = stringResource(R.string.pref_webtoon_side_padding), - entries = mapOf( - 0 to stringResource(R.string.webtoon_side_padding_0), - 5 to stringResource(R.string.webtoon_side_padding_5), - 10 to stringResource(R.string.webtoon_side_padding_10), - 15 to stringResource(R.string.webtoon_side_padding_15), - 20 to stringResource(R.string.webtoon_side_padding_20), - 25 to stringResource(R.string.webtoon_side_padding_25), - ), + subtitle = stringResource(R.string.percentage, webtoonSidePadding), + min = ReaderPreferences.WEBTOON_PADDING_MIN, + max = ReaderPreferences.WEBTOON_PADDING_MAX, + onValueChanged = { + webtoonSidePaddingPref.set(it) + true + }, ), Preference.PreferenceItem.ListPreference( pref = readerPreferences.readerHideThreshold(), diff --git a/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt b/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt index 43eea76485..02738eedac 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt @@ -15,7 +15,7 @@ import tachiyomi.presentation.core.components.RadioItem @Composable internal fun ColumnScope.GeneralPage(screenModel: ReaderSettingsScreenModel) { // TODO: show this in a nicer way - HeadingItem(stringResource(R.string.pref_reader_theme)) + HeadingItem(R.string.pref_reader_theme) val readerTheme by screenModel.preferences.readerTheme().collectAsState() listOf( R.string.black_background to 1, 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 0cf0ed29ca..e330b99449 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 @@ -2,9 +2,174 @@ package eu.kanade.presentation.reader.settings import androidx.compose.foundation.layout.ColumnScope import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.res.stringResource +import eu.kanade.presentation.util.collectAsState +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel +import eu.kanade.tachiyomi.util.system.isReleaseBuildType +import tachiyomi.presentation.core.components.CheckboxItem +import tachiyomi.presentation.core.components.HeadingItem +import tachiyomi.presentation.core.components.SliderItem @Composable internal fun ColumnScope.ReadingModePage(screenModel: ReaderSettingsScreenModel) { - // TODO + HeadingItem(R.string.pref_category_for_this_series) + + // Reading mode + // Rotation type + + // if (pager) + PagerViewerSettings(screenModel) + + WebtoonViewerSettings(screenModel) +} + +@Composable +private fun ColumnScope.PagerViewerSettings(screenModel: ReaderSettingsScreenModel) { + HeadingItem(R.string.pager_viewer) + + // Tap zones + // Invert tap zones + // Scale type + // Zoom start position + + val cropBorders by screenModel.preferences.cropBorders().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_crop_borders), + checked = cropBorders, + onClick = { + screenModel.togglePreference(ReaderPreferences::cropBorders) + }, + ) + + val landscapeZoom by screenModel.preferences.landscapeZoom().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_landscape_zoom), + checked = landscapeZoom, + onClick = { + screenModel.togglePreference(ReaderPreferences::landscapeZoom) + }, + ) + + val navigateToPan by screenModel.preferences.navigateToPan().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_navigate_pan), + checked = navigateToPan, + onClick = { + screenModel.togglePreference(ReaderPreferences::navigateToPan) + }, + ) + + val dualPageSplitPaged by screenModel.preferences.dualPageSplitPaged().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_dual_page_split), + checked = dualPageSplitPaged, + onClick = { + screenModel.togglePreference(ReaderPreferences::dualPageSplitPaged) + }, + ) + + if (dualPageSplitPaged) { + val dualPageInvertPaged by screenModel.preferences.dualPageInvertPaged().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_dual_page_invert), + checked = dualPageInvertPaged, + onClick = { + screenModel.togglePreference(ReaderPreferences::dualPageInvertPaged) + }, + ) + } + + val dualPageRotateToFit by screenModel.preferences.dualPageRotateToFit().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_page_rotate), + checked = dualPageRotateToFit, + onClick = { + screenModel.togglePreference(ReaderPreferences::dualPageRotateToFit) + }, + ) + + if (dualPageRotateToFit) { + val dualPageRotateToFitInvert by screenModel.preferences.dualPageRotateToFitInvert().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_page_rotate_invert), + checked = dualPageRotateToFitInvert, + onClick = { + screenModel.togglePreference(ReaderPreferences::dualPageRotateToFitInvert) + }, + ) + } +} + +@Composable +private fun ColumnScope.WebtoonViewerSettings(screenModel: ReaderSettingsScreenModel) { + HeadingItem(R.string.webtoon_viewer) + + // TODO: Tap zones + // TODO: Invert tap zones + + val webtoonSidePadding by screenModel.preferences.webtoonSidePadding().collectAsState() + SliderItem( + label = stringResource(R.string.pref_webtoon_side_padding), + min = ReaderPreferences.WEBTOON_PADDING_MIN, + max = ReaderPreferences.WEBTOON_PADDING_MAX, + value = webtoonSidePadding, + valueText = stringResource(R.string.percentage, webtoonSidePadding), + onChange = { + screenModel.preferences.webtoonSidePadding().set(it) + }, + ) + + val cropBordersWebtoon by screenModel.preferences.cropBordersWebtoon().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_crop_borders), + checked = cropBordersWebtoon, + onClick = { + screenModel.togglePreference(ReaderPreferences::cropBordersWebtoon) + }, + ) + + val dualPageSplitWebtoon by screenModel.preferences.dualPageSplitWebtoon().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_dual_page_split), + checked = dualPageSplitWebtoon, + onClick = { + screenModel.togglePreference(ReaderPreferences::dualPageSplitWebtoon) + }, + ) + + if (dualPageSplitWebtoon) { + val dualPageInvertWebtoon by screenModel.preferences.dualPageInvertWebtoon() + .collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_dual_page_invert), + checked = dualPageInvertWebtoon, + onClick = { + screenModel.togglePreference(ReaderPreferences::dualPageInvertWebtoon) + }, + ) + } + + if (!isReleaseBuildType) { + val longStripSplitWebtoon by screenModel.preferences.longStripSplitWebtoon() + .collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_long_strip_split), + checked = longStripSplitWebtoon, + onClick = { + screenModel.togglePreference(ReaderPreferences::longStripSplitWebtoon) + }, + ) + } + + val webtoonDoubleTapZoomEnabled by screenModel.preferences.webtoonDoubleTapZoomEnabled().collectAsState() + CheckboxItem( + label = stringResource(R.string.pref_double_tap_zoom), + checked = webtoonDoubleTapZoomEnabled, + onClick = { + screenModel.togglePreference(ReaderPreferences::webtoonDoubleTapZoomEnabled) + }, + ) } 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 b2b82ea97e..b18a5682ef 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 @@ -52,7 +52,7 @@ class ReaderPreferences( fun cropBordersWebtoon() = preferenceStore.getBoolean("crop_borders_webtoon", false) - fun webtoonSidePadding() = preferenceStore.getInt("webtoon_side_padding", 0) + fun webtoonSidePadding() = preferenceStore.getInt("webtoon_side_padding", WEBTOON_PADDING_MIN) fun readerHideThreshold() = preferenceStore.getEnum("reader_hide_threshold", ReaderHideThreshold.LOW) @@ -135,4 +135,9 @@ class ReaderPreferences( LOW(31), LOWEST(47), } + + companion object { + const val WEBTOON_PADDING_MIN = 0 + const val WEBTOON_PADDING_MAX = 25 + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsSheet.kt index 8fde6830a3..50529e4cb7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsSheet.kt @@ -6,13 +6,11 @@ import androidx.lifecycle.lifecycleScope import com.google.android.material.bottomsheet.BottomSheetDialog import eu.kanade.domain.manga.model.orientationType import eu.kanade.domain.manga.model.readingModeType -import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.ReaderReadingModeSettingsBinding import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer import eu.kanade.tachiyomi.util.preference.bindToPreference -import eu.kanade.tachiyomi.util.system.isReleaseBuildType import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import uy.kohesive.injekt.injectLazy @@ -65,47 +63,17 @@ class ReaderSettingsSheet( binding.pagerPrefsGroup.root.isVisible = true binding.pagerPrefsGroup.tappingInverted.bindToPreference(readerPreferences.pagerNavInverted(), ReaderPreferences.TappingInvertMode::class.java) - binding.pagerPrefsGroup.navigatePan.bindToPreference(readerPreferences.navigateToPan()) binding.pagerPrefsGroup.pagerNav.bindToPreference(readerPreferences.navigationModePager()) readerPreferences.navigationModePager().changes() .onEach { val isTappingEnabled = it != 5 binding.pagerPrefsGroup.tappingInverted.isVisible = isTappingEnabled - binding.pagerPrefsGroup.navigatePan.isVisible = isTappingEnabled } .launchIn(activity.lifecycleScope) - // Makes so that landscape zoom gets hidden away when image scale type is not fit screen binding.pagerPrefsGroup.scaleType.bindToPreference(readerPreferences.imageScaleType(), 1) - readerPreferences.imageScaleType().changes() - .onEach { binding.pagerPrefsGroup.landscapeZoom.isVisible = it == 1 } - .launchIn(activity.lifecycleScope) - binding.pagerPrefsGroup.landscapeZoom.bindToPreference(readerPreferences.landscapeZoom()) binding.pagerPrefsGroup.zoomStart.bindToPreference(readerPreferences.zoomStart(), 1) - binding.pagerPrefsGroup.cropBorders.bindToPreference(readerPreferences.cropBorders()) - - binding.pagerPrefsGroup.dualPageSplit.bindToPreference(readerPreferences.dualPageSplitPaged()) - readerPreferences.dualPageSplitPaged().changes() - .onEach { - binding.pagerPrefsGroup.dualPageInvert.isVisible = it - if (it) { - binding.pagerPrefsGroup.dualPageRotateToFit.isChecked = false - } - } - .launchIn(activity.lifecycleScope) - binding.pagerPrefsGroup.dualPageInvert.bindToPreference(readerPreferences.dualPageInvertPaged()) - - binding.pagerPrefsGroup.dualPageRotateToFit.bindToPreference(readerPreferences.dualPageRotateToFit()) - readerPreferences.dualPageRotateToFit().changes() - .onEach { - binding.pagerPrefsGroup.dualPageRotateToFitInvert.isVisible = it - if (it) { - binding.pagerPrefsGroup.dualPageSplit.isChecked = false - } - } - .launchIn(activity.lifecycleScope) - binding.pagerPrefsGroup.dualPageRotateToFitInvert.bindToPreference(readerPreferences.dualPageRotateToFitInvert()) } private fun initWebtoonPreferences() { @@ -118,19 +86,5 @@ class ReaderSettingsSheet( readerPreferences.navigationModeWebtoon().changes() .onEach { binding.webtoonPrefsGroup.tappingInverted.isVisible = it != 5 } .launchIn(activity.lifecycleScope) - binding.webtoonPrefsGroup.cropBordersWebtoon.bindToPreference(readerPreferences.cropBordersWebtoon()) - binding.webtoonPrefsGroup.webtoonSidePadding.bindToIntPreference(readerPreferences.webtoonSidePadding(), R.array.webtoon_side_padding_values) - - binding.webtoonPrefsGroup.dualPageSplit.bindToPreference(readerPreferences.dualPageSplitWebtoon()) - // Makes it so that dual page invert gets hidden away when dual page split is turned off - readerPreferences.dualPageSplitWebtoon().changes() - .onEach { binding.webtoonPrefsGroup.dualPageInvert.isVisible = it } - .launchIn(activity.lifecycleScope) - binding.webtoonPrefsGroup.dualPageInvert.bindToPreference(readerPreferences.dualPageInvertWebtoon()) - - 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/widget/MaterialSpinnerView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt index b57abbba5b..57289daf1e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt @@ -7,7 +7,6 @@ import android.view.Gravity import android.view.LayoutInflater import android.view.MenuItem import android.widget.FrameLayout -import androidx.annotation.ArrayRes import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.widget.PopupMenu @@ -99,17 +98,6 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att } } - fun bindToIntPreference(pref: Preference, @ArrayRes intValuesResource: Int, block: ((Int) -> Unit)? = null) { - val intValues = resources.getStringArray(intValuesResource).map { it.toIntOrNull() } - setSelection(intValues.indexOf(pref.get())) - - popup = makeSettingsPopup(pref, intValues, block) - setOnTouchListener(popup?.dragToOpenListener) - setOnClickListener { - popup?.show() - } - } - private fun > makeSettingsPopup(preference: Preference, clazz: Class): PopupMenu { return createPopupMenu { pos -> onItemSelectedListener?.invoke(pos) diff --git a/app/src/main/res/layout/reader_pager_settings.xml b/app/src/main/res/layout/reader_pager_settings.xml index c48c467296..f79bcfa114 100644 --- a/app/src/main/res/layout/reader_pager_settings.xml +++ b/app/src/main/res/layout/reader_pager_settings.xml @@ -1,7 +1,6 @@ @@ -44,77 +43,4 @@ android:entries="@array/zoom_start" app:title="@string/pref_zoom_start" /> - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/reader_reading_mode_settings.xml b/app/src/main/res/layout/reader_reading_mode_settings.xml index eeb733d47e..e825c229a0 100644 --- a/app/src/main/res/layout/reader_reading_mode_settings.xml +++ b/app/src/main/res/layout/reader_reading_mode_settings.xml @@ -36,7 +36,6 @@ android:entries="@array/rotation_type" app:title="@string/rotation_type" /> - - @@ -30,64 +29,4 @@ android:entries="@array/invert_tapping_mode" app:title="@string/pref_read_with_tapping_inverted" /> - - - - - - - - - - - - - - diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 77161bfadb..d9403c687a 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -18,24 +18,6 @@ @string/scale_type_smart_fit - - @string/webtoon_side_padding_0 - @string/webtoon_side_padding_5 - @string/webtoon_side_padding_10 - @string/webtoon_side_padding_15 - @string/webtoon_side_padding_20 - @string/webtoon_side_padding_25 - - - - 0 - 5 - 10 - 15 - 20 - 25 - - @string/zoom_start_automatic @string/zoom_start_left diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 00c91a7b09..fdb075c62a 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -434,12 +434,8 @@ Reading mode Reading Side padding - None - 5% - 10% - 15% - 20% - 25% + + %1$d\%% Sensitivity for hiding menu on scroll Highest High