From e40b8d537c2727a9867fedf8971afd01237a661f Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 15 Jul 2023 10:47:56 -0400 Subject: [PATCH] Move all pager/webtoon reader setting to Compose sheet --- .../eu/kanade/domain/base/BasePreferences.kt | 3 +- .../settings/screen/SettingsReaderScreen.kt | 34 +++----- .../reader/settings/ReadingModePage.kt | 80 ++++++++++++++++--- .../ui/reader/setting/ReaderPreferences.kt | 41 ++++++++-- .../ui/reader/setting/ReaderSettingsSheet.kt | 52 ------------ .../tachiyomi/widget/MaterialSpinnerView.kt | 37 --------- .../main/res/layout/reader_pager_settings.xml | 46 ----------- .../layout/reader_reading_mode_settings.xml | 27 ------- .../res/layout/reader_webtoon_settings.xml | 32 -------- app/src/main/res/values/arrays.xml | 41 ---------- 10 files changed, 121 insertions(+), 272 deletions(-) delete mode 100644 app/src/main/res/layout/reader_pager_settings.xml delete mode 100644 app/src/main/res/layout/reader_webtoon_settings.xml diff --git a/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt b/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt index ba3cebc86..eb69664f7 100644 --- a/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt +++ b/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt @@ -1,6 +1,7 @@ package eu.kanade.domain.base import android.content.Context +import androidx.annotation.StringRes import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.isPreviewBuildType import eu.kanade.tachiyomi.util.system.isReleaseBuildType @@ -19,7 +20,7 @@ class BasePreferences( fun acraEnabled() = preferenceStore.getBoolean("acra.enable", isPreviewBuildType || isReleaseBuildType) - enum class ExtensionInstaller(val titleResId: Int) { + enum class ExtensionInstaller(@StringRes val titleResId: Int) { LEGACY(R.string.ext_installer_legacy), PACKAGEINSTALLER(R.string.ext_installer_packageinstaller), SHIZUKU(R.string.ext_installer_shizuku), 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 31f60acfd..0a19a72c2 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 @@ -7,7 +7,6 @@ import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.platform.LocalView -import androidx.compose.ui.res.stringArrayResource import androidx.compose.ui.res.stringResource import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.util.collectAsState @@ -164,9 +163,9 @@ object SettingsReaderScreen : SearchableSettings { Preference.PreferenceItem.ListPreference( pref = navModePref, title = stringResource(R.string.pref_viewer_nav), - entries = stringArrayResource(id = R.array.pager_nav).let { - it.indices.zip(it).toMap() - }, + entries = ReaderPreferences.TapZones + .mapIndexed { index, it -> index to stringResource(it) } + .toMap(), ), Preference.PreferenceItem.ListPreference( pref = readerPreferences.pagerNavInverted(), @@ -182,25 +181,16 @@ object SettingsReaderScreen : SearchableSettings { Preference.PreferenceItem.ListPreference( pref = imageScaleTypePref, title = stringResource(R.string.pref_image_scale_type), - entries = mapOf( - 1 to stringResource(R.string.scale_type_fit_screen), - 2 to stringResource(R.string.scale_type_stretch), - 3 to stringResource(R.string.scale_type_fit_width), - 4 to stringResource(R.string.scale_type_fit_height), - 5 to stringResource(R.string.scale_type_original_size), - 6 to stringResource(R.string.scale_type_smart_fit), - ), + entries = ReaderPreferences.ImageScaleType + .mapIndexed { index, it -> index + 1 to stringResource(it) } + .toMap(), ), Preference.PreferenceItem.ListPreference( pref = readerPreferences.zoomStart(), title = stringResource(R.string.pref_zoom_start), - entries = mapOf( - 1 to stringResource(R.string.zoom_start_automatic), - 2 to stringResource(R.string.zoom_start_left), - 3 to stringResource(R.string.zoom_start_right), - 4 to stringResource(R.string.zoom_start_center), - ), - + entries = ReaderPreferences.ZoomStart + .mapIndexed { index, it -> index + 1 to stringResource(it) } + .toMap(), ), Preference.PreferenceItem.SwitchPreference( pref = readerPreferences.cropBorders(), @@ -265,9 +255,9 @@ object SettingsReaderScreen : SearchableSettings { Preference.PreferenceItem.ListPreference( pref = navModePref, title = stringResource(R.string.pref_viewer_nav), - entries = stringArrayResource(id = R.array.webtoon_nav).let { - it.indices.zip(it).toMap() - }, + entries = ReaderPreferences.TapZones + .mapIndexed { index, it -> index to stringResource(it) } + .toMap(), ), Preference.PreferenceItem.ListPreference( pref = readerPreferences.webtoonNavInverted(), 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 ff710a76d..48d002a1b 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 @@ -12,17 +12,23 @@ 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.RadioItem import tachiyomi.presentation.core.components.SliderItem import java.text.NumberFormat @Composable internal fun ColumnScope.ReadingModePage(screenModel: ReaderSettingsScreenModel) { + HeadingItem("This is still a WIP, the UI will be improved soon") + HeadingItem(R.string.pref_category_for_this_series) - // Reading mode - // Rotation type + // TODO: Reading mode + HeadingItem(R.string.pref_category_reading_mode) - // if (pager) + // TODO: Rotation type + HeadingItem(R.string.rotation_type) + + // TODO: if (pager) PagerViewerSettings(screenModel) WebtoonViewerSettings(screenModel) @@ -32,10 +38,47 @@ internal fun ColumnScope.ReadingModePage(screenModel: ReaderSettingsScreenModel) private fun ColumnScope.PagerViewerSettings(screenModel: ReaderSettingsScreenModel) { HeadingItem(R.string.pager_viewer) - // Tap zones - // Invert tap zones - // Scale type - // Zoom start position + val navigationModePager by screenModel.preferences.navigationModePager().collectAsState() + HeadingItem(R.string.pref_viewer_nav) + ReaderPreferences.TapZones.mapIndexed { index, titleResId -> + RadioItem( + label = stringResource(titleResId), + selected = navigationModePager == index, + onClick = { screenModel.preferences.navigationModePager().set(index) }, + ) + } + + if (navigationModePager != 5) { + val pagerNavInverted by screenModel.preferences.pagerNavInverted().collectAsState() + HeadingItem(R.string.pref_read_with_tapping_inverted) + ReaderPreferences.TappingInvertMode.values().map { + RadioItem( + label = stringResource(it.titleResId), + selected = pagerNavInverted == it, + onClick = { screenModel.preferences.pagerNavInverted().set(it) }, + ) + } + } + + val imageScaleType by screenModel.preferences.imageScaleType().collectAsState() + HeadingItem(R.string.pref_image_scale_type) + ReaderPreferences.ImageScaleType.mapIndexed { index, it -> + RadioItem( + label = stringResource(it), + selected = imageScaleType == index + 1, + onClick = { screenModel.preferences.imageScaleType().set(index + 1) }, + ) + } + + val zoomStart by screenModel.preferences.zoomStart().collectAsState() + HeadingItem(R.string.pref_zoom_start) + ReaderPreferences.ZoomStart.mapIndexed { index, it -> + RadioItem( + label = stringResource(it), + selected = zoomStart == index + 1, + onClick = { screenModel.preferences.zoomStart().set(index + 1) }, + ) + } val cropBorders by screenModel.preferences.cropBorders().collectAsState() CheckboxItem( @@ -111,8 +154,27 @@ private fun ColumnScope.WebtoonViewerSettings(screenModel: ReaderSettingsScreenM HeadingItem(R.string.webtoon_viewer) - // TODO: Tap zones - // TODO: Invert tap zones + val navigationModeWebtoon by screenModel.preferences.navigationModeWebtoon().collectAsState() + HeadingItem(R.string.pref_viewer_nav) + ReaderPreferences.TapZones.mapIndexed { index, titleResId -> + RadioItem( + label = stringResource(titleResId), + selected = navigationModeWebtoon == index, + onClick = { screenModel.preferences.navigationModeWebtoon().set(index) }, + ) + } + + if (navigationModeWebtoon != 5) { + val webtoonNavInverted by screenModel.preferences.webtoonNavInverted().collectAsState() + HeadingItem(R.string.pref_read_with_tapping_inverted) + ReaderPreferences.TappingInvertMode.values().map { + RadioItem( + label = stringResource(it.titleResId), + selected = webtoonNavInverted == it, + onClick = { screenModel.preferences.webtoonNavInverted().set(it) }, + ) + } + } val webtoonSidePadding by screenModel.preferences.webtoonSidePadding().collectAsState() SliderItem( 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 b18a5682e..23a5beb13 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 @@ -1,5 +1,7 @@ package eu.kanade.tachiyomi.ui.reader.setting +import androidx.annotation.StringRes +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.isReleaseBuildType import tachiyomi.core.preference.PreferenceStore import tachiyomi.core.preference.getEnum @@ -122,11 +124,15 @@ class ReaderPreferences( // endregion - enum class TappingInvertMode(val shouldInvertHorizontal: Boolean = false, val shouldInvertVertical: Boolean = false) { - NONE, - HORIZONTAL(shouldInvertHorizontal = true), - VERTICAL(shouldInvertVertical = true), - BOTH(shouldInvertHorizontal = true, shouldInvertVertical = true), + enum class TappingInvertMode( + @StringRes val titleResId: Int, + val shouldInvertHorizontal: Boolean = false, + val shouldInvertVertical: Boolean = false, + ) { + NONE(R.string.tapping_inverted_none), + HORIZONTAL(R.string.tapping_inverted_horizontal, shouldInvertHorizontal = true), + VERTICAL(R.string.tapping_inverted_vertical, shouldInvertVertical = true), + BOTH(R.string.tapping_inverted_both, shouldInvertHorizontal = true, shouldInvertVertical = true), } enum class ReaderHideThreshold(val threshold: Int) { @@ -139,5 +145,30 @@ class ReaderPreferences( companion object { const val WEBTOON_PADDING_MIN = 0 const val WEBTOON_PADDING_MAX = 25 + + val TapZones = listOf( + R.string.label_default, + R.string.l_nav, + R.string.kindlish_nav, + R.string.edge_nav, + R.string.right_and_left_nav, + R.string.disabled_nav, + ) + + val ImageScaleType = listOf( + R.string.scale_type_fit_screen, + R.string.scale_type_stretch, + R.string.scale_type_fit_width, + R.string.scale_type_fit_height, + R.string.scale_type_original_size, + R.string.scale_type_smart_fit, + ) + + val ZoomStart = listOf( + R.string.zoom_start_automatic, + R.string.zoom_start_left, + R.string.zoom_start_right, + R.string.zoom_start_center, + ) } } 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 50529e4cb..a54aa233b 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 @@ -1,26 +1,16 @@ package eu.kanade.tachiyomi.ui.reader.setting import android.os.Bundle -import androidx.core.view.isVisible -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.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 kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach -import uy.kohesive.injekt.injectLazy class ReaderSettingsSheet( private val activity: ReaderActivity, ) : BottomSheetDialog(activity) { - private val readerPreferences: ReaderPreferences by injectLazy() - private lateinit var binding: ReaderReadingModeSettingsBinding override fun onCreate(savedInstanceState: Bundle?) { @@ -30,24 +20,12 @@ class ReaderSettingsSheet( setContentView(binding.root) initGeneralPreferences() - - when (activity.viewModel.state.value.viewer) { - is PagerViewer -> initPagerPreferences() - is WebtoonViewer -> initWebtoonPreferences() - } } private fun initGeneralPreferences() { binding.viewer.onItemSelectedListener = { position -> val readingModeType = ReadingModeType.fromSpinner(position) activity.viewModel.setMangaReadingMode(readingModeType.flagValue) - - val mangaViewer = activity.viewModel.getMangaReadingMode() - if (mangaViewer == ReadingModeType.WEBTOON.flagValue || mangaViewer == ReadingModeType.CONTINUOUS_VERTICAL.flagValue) { - initWebtoonPreferences() - } else { - initPagerPreferences() - } } binding.viewer.setSelection(activity.viewModel.manga?.readingModeType?.let { ReadingModeType.fromPreference(it.toInt()).prefValue } ?: ReadingModeType.DEFAULT.prefValue) @@ -57,34 +35,4 @@ class ReaderSettingsSheet( } binding.rotationMode.setSelection(activity.viewModel.manga?.orientationType?.let { OrientationType.fromPreference(it.toInt()).prefValue } ?: OrientationType.DEFAULT.prefValue) } - - private fun initPagerPreferences() { - binding.webtoonPrefsGroup.root.isVisible = false - binding.pagerPrefsGroup.root.isVisible = true - - binding.pagerPrefsGroup.tappingInverted.bindToPreference(readerPreferences.pagerNavInverted(), ReaderPreferences.TappingInvertMode::class.java) - - binding.pagerPrefsGroup.pagerNav.bindToPreference(readerPreferences.navigationModePager()) - readerPreferences.navigationModePager().changes() - .onEach { - val isTappingEnabled = it != 5 - binding.pagerPrefsGroup.tappingInverted.isVisible = isTappingEnabled - } - .launchIn(activity.lifecycleScope) - binding.pagerPrefsGroup.scaleType.bindToPreference(readerPreferences.imageScaleType(), 1) - - binding.pagerPrefsGroup.zoomStart.bindToPreference(readerPreferences.zoomStart(), 1) - } - - private fun initWebtoonPreferences() { - binding.pagerPrefsGroup.root.isVisible = false - binding.webtoonPrefsGroup.root.isVisible = true - - binding.webtoonPrefsGroup.tappingInverted.bindToPreference(readerPreferences.webtoonNavInverted(), ReaderPreferences.TappingInvertMode::class.java) - - binding.webtoonPrefsGroup.webtoonNav.bindToPreference(readerPreferences.navigationModeWebtoon()) - readerPreferences.navigationModeWebtoon().changes() - .onEach { binding.webtoonPrefsGroup.tappingInverted.isVisible = it != 5 } - .launchIn(activity.lifecycleScope) - } } 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 57289daf1..54160cf71 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt @@ -77,43 +77,6 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att binding.details.text = entries.getOrNull(selection).orEmpty() } - fun bindToPreference(pref: Preference, offset: Int = 0, block: ((Int) -> Unit)? = null) { - setSelection(pref.get() - offset) - - popup = makeSettingsPopup(pref, offset, block) - setOnTouchListener(popup?.dragToOpenListener) - setOnClickListener { - popup?.show() - } - } - - fun > bindToPreference(pref: Preference, clazz: Class) { - val enumConstants = clazz.enumConstants - enumConstants?.indexOf(pref.get())?.let { setSelection(it) } - - popup = makeSettingsPopup(pref, clazz) - setOnTouchListener(popup?.dragToOpenListener) - setOnClickListener { - popup?.show() - } - } - - private fun > makeSettingsPopup(preference: Preference, clazz: Class): PopupMenu { - return createPopupMenu { pos -> - onItemSelectedListener?.invoke(pos) - - val enumConstants = clazz.enumConstants - enumConstants?.get(pos)?.let { enumValue -> preference.set(enumValue) } - } - } - - private fun makeSettingsPopup(preference: Preference, intValues: List, block: ((Int) -> Unit)? = null): PopupMenu { - return createPopupMenu { pos -> - preference.set(intValues[pos] ?: 0) - block?.invoke(pos) - } - } - private fun makeSettingsPopup(preference: Preference, offset: Int = 0, block: ((Int) -> Unit)? = null): PopupMenu { return createPopupMenu { pos -> preference.set(pos + offset) diff --git a/app/src/main/res/layout/reader_pager_settings.xml b/app/src/main/res/layout/reader_pager_settings.xml deleted file mode 100644 index f79bcfa11..000000000 --- a/app/src/main/res/layout/reader_pager_settings.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - 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 e825c229a..39b824939 100644 --- a/app/src/main/res/layout/reader_reading_mode_settings.xml +++ b/app/src/main/res/layout/reader_reading_mode_settings.xml @@ -1,7 +1,6 @@ @@ -10,17 +9,6 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - - - - - diff --git a/app/src/main/res/layout/reader_webtoon_settings.xml b/app/src/main/res/layout/reader_webtoon_settings.xml deleted file mode 100644 index 00e970665..000000000 --- a/app/src/main/res/layout/reader_webtoon_settings.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index d9403c687..11d827db9 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -9,22 +9,6 @@ @string/vertical_plus_viewer - - @string/scale_type_fit_screen - @string/scale_type_stretch - @string/scale_type_fit_width - @string/scale_type_fit_height - @string/scale_type_original_size - @string/scale_type_smart_fit - - - - @string/zoom_start_automatic - @string/zoom_start_left - @string/zoom_start_right - @string/zoom_start_center - - @string/label_default @string/rotation_free @@ -34,29 +18,4 @@ @string/rotation_force_landscape @string/rotation_reverse_portrait - - - @string/tapping_inverted_none - @string/tapping_inverted_horizontal - @string/tapping_inverted_vertical - @string/tapping_inverted_both - - - - @string/label_default - @string/l_nav - @string/kindlish_nav - @string/edge_nav - @string/right_and_left_nav - @string/disabled_nav - - - - @string/label_default - @string/l_nav - @string/kindlish_nav - @string/edge_nav - @string/right_and_left_nav - @string/disabled_nav -