Move boolean reading mode prefs to Compose sheet

Also allow webtoon side padding to be any amount between 0 - 25%.
This commit is contained in:
arkon 2023-07-11 22:24:16 -04:00
parent 3bd2cad45f
commit 2f0133986a
12 changed files with 187 additions and 233 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Int>, @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 <T : Enum<T>> makeSettingsPopup(preference: Preference<T>, clazz: Class<T>): PopupMenu {
return createPopupMenu { pos ->
onItemSelectedListener?.invoke(pos)

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -44,77 +43,4 @@
android:entries="@array/zoom_start"
app:title="@string/pref_zoom_start" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/crop_borders"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_crop_borders"
android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/landscape_zoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_landscape_zoom"
android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/navigate_pan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_navigate_pan"
android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/dual_page_split"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_dual_page_split"
android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/dual_page_invert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_dual_page_invert"
android:textColor="?android:attr/textColorSecondary"
android:visibility="gone"
tools:visibility="visible" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/dual_page_rotate_to_fit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_page_rotate"
android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/dual_page_rotate_to_fit_invert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_page_rotate_invert"
android:textColor="?android:attr/textColorSecondary"
android:visibility="gone"
tools:visibility="visible" />
<androidx.constraintlayout.widget.Group
android:id="@+id/tapping_prefs_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="pager_nav,tapping_inverted,dual_page_split,dual_page_invert,dual_page_rotate_to_fit,dual_page_rotate_to_fit_invert" />
</LinearLayout>

View File

@ -36,7 +36,6 @@
android:entries="@array/rotation_type"
app:title="@string/rotation_type" />
<!-- Pager preferences -->
<include
android:id="@+id/pager_prefs_group"
layout="@layout/reader_pager_settings"
@ -45,7 +44,6 @@
android:visibility="gone"
tools:visibility="visible" />
<!-- Webtoon preferences -->
<include
android:id="@+id/webtoon_prefs_group"
layout="@layout/reader_webtoon_settings"

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -30,64 +29,4 @@
android:entries="@array/invert_tapping_mode"
app:title="@string/pref_read_with_tapping_inverted" />
<eu.kanade.tachiyomi.widget.MaterialSpinnerView
android:id="@+id/webtoon_side_padding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/webtoon_side_padding"
app:title="@string/pref_webtoon_side_padding" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/crop_borders_webtoon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_crop_borders"
android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/dual_page_split"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_dual_page_split"
android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/dual_page_invert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="@string/pref_dual_page_invert"
android:textColor="?android:attr/textColorSecondary"
android:visibility="gone"
tools:visibility="visible" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/long_strip_split"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:text="@string/pref_long_strip_split"
android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/double_tap_zoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:text="@string/pref_double_tap_zoom"
android:textColor="?android:attr/textColorSecondary" />
<androidx.constraintlayout.widget.Group
android:id="@+id/tapping_prefs_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="webtoon_nav,tapping_inverted,dual_page_split,dual_page_invert" />
</LinearLayout>

View File

@ -18,24 +18,6 @@
<item>@string/scale_type_smart_fit</item>
</string-array>
<string-array name="webtoon_side_padding">
<item>@string/webtoon_side_padding_0</item>
<item>@string/webtoon_side_padding_5</item>
<item>@string/webtoon_side_padding_10</item>
<item>@string/webtoon_side_padding_15</item>
<item>@string/webtoon_side_padding_20</item>
<item>@string/webtoon_side_padding_25</item>
</string-array>
<string-array name="webtoon_side_padding_values">
<item>0</item>
<item>5</item>
<item>10</item>
<item>15</item>
<item>20</item>
<item>25</item>
</string-array>
<string-array name="zoom_start">
<item>@string/zoom_start_automatic</item>
<item>@string/zoom_start_left</item>

View File

@ -434,12 +434,8 @@
<string name="pref_category_reading_mode">Reading mode</string>
<string name="pref_category_reading">Reading</string>
<string name="pref_webtoon_side_padding">Side padding</string>
<string name="webtoon_side_padding_0">None</string>
<string name="webtoon_side_padding_5">5%</string>
<string name="webtoon_side_padding_10">10%</string>
<string name="webtoon_side_padding_15">15%</string>
<string name="webtoon_side_padding_20">20%</string>
<string name="webtoon_side_padding_25">25%</string>
<!-- A percentage amount like "12%". "%1$d" is the number and "\%%" is the "%" sign. -->
<string name="percentage">%1$d\%%</string>
<string name="pref_hide_threshold">Sensitivity for hiding menu on scroll</string>
<string name="pref_highest">Highest</string>
<string name="pref_high">High</string>