From 9e67abcc8a1e7ca90c0a92acc563e998a7a99886 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 5 Nov 2023 11:25:08 -0500 Subject: [PATCH] Add separate default/apply buttons to reading mode/orientation selection dialogs Related to #3453 --- .../reader/OrientationSelectDialog.kt | 41 ++++++--- .../reader/ReadingModeSelectDialog.kt | 38 +++++--- .../reader/appbars/ReaderAppBars.kt | 1 + .../ChapterNavigator.kt | 2 +- .../reader/components/ModeSelectionDialog.kt | 89 +++++++++++++++++++ i18n/src/main/res/values/strings.xml | 2 + 6 files changed, 149 insertions(+), 24 deletions(-) rename app/src/main/java/eu/kanade/presentation/reader/{appbars => components}/ChapterNavigator.kt (99%) create mode 100644 app/src/main/java/eu/kanade/presentation/reader/components/ModeSelectionDialog.kt diff --git a/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt b/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt index 3d0e1143ea..9d3b734cb3 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt @@ -1,22 +1,23 @@ package eu.kanade.presentation.reader -import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.grid.items import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource import androidx.compose.ui.tooling.preview.PreviewLightDark -import androidx.compose.ui.unit.dp import eu.kanade.domain.manga.model.readerOrientation import eu.kanade.presentation.components.AdaptiveSheet +import eu.kanade.presentation.reader.components.ModeSelectionDialog import eu.kanade.presentation.theme.TachiyomiTheme import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation @@ -24,6 +25,8 @@ import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import tachiyomi.presentation.core.components.SettingsIconGrid import tachiyomi.presentation.core.components.material.IconToggleButton +private val ReaderOrientationsWithoutDefault = ReaderOrientation.entries - ReaderOrientation.DEFAULT + @Composable fun OrientationSelectDialog( onDismissRequest: () -> Unit, @@ -50,13 +53,22 @@ private fun DialogContent( orientation: ReaderOrientation, onChangeOrientation: (ReaderOrientation) -> Unit, ) { - Box(modifier = Modifier.padding(vertical = 16.dp)) { + var selected by remember { mutableStateOf(orientation) } + + ModeSelectionDialog( + onUseDefault = { + onChangeOrientation( + ReaderOrientation.DEFAULT, + ) + }.takeIf { orientation != ReaderOrientation.DEFAULT }, + onApply = { onChangeOrientation(selected) }, + ) { SettingsIconGrid(R.string.rotation_type) { - items(ReaderOrientation.entries) { mode -> + items(ReaderOrientationsWithoutDefault) { mode -> IconToggleButton( - checked = mode == orientation, + checked = mode == selected, onCheckedChange = { - onChangeOrientation(mode) + selected = mode }, modifier = Modifier.fillMaxWidth(), imageVector = ImageVector.vectorResource(mode.iconRes), @@ -72,10 +84,17 @@ private fun DialogContent( private fun DialogContentPreview() { TachiyomiTheme { Surface { - DialogContent( - orientation = ReaderOrientation.DEFAULT, - onChangeOrientation = {}, - ) + Column { + DialogContent( + orientation = ReaderOrientation.DEFAULT, + onChangeOrientation = {}, + ) + + DialogContent( + orientation = ReaderOrientation.FREE, + onChangeOrientation = {}, + ) + } } } } diff --git a/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt b/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt index e9a669e175..a34d14e5f5 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt @@ -1,15 +1,15 @@ package eu.kanade.presentation.reader -import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.grid.items -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource @@ -17,13 +17,15 @@ import androidx.compose.ui.res.vectorResource import androidx.compose.ui.tooling.preview.PreviewLightDark import eu.kanade.domain.manga.model.readingMode import eu.kanade.presentation.components.AdaptiveSheet +import eu.kanade.presentation.reader.components.ModeSelectionDialog import eu.kanade.presentation.theme.TachiyomiTheme import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import tachiyomi.presentation.core.components.SettingsIconGrid import tachiyomi.presentation.core.components.material.IconToggleButton -import tachiyomi.presentation.core.components.material.padding + +private val ReadingModesWithoutDefault = ReadingMode.entries - ReadingMode.DEFAULT @Composable fun ReadingModeSelectDialog( @@ -51,13 +53,18 @@ private fun DialogContent( readingMode: ReadingMode, onChangeReadingMode: (ReadingMode) -> Unit, ) { - Box(modifier = Modifier.padding(vertical = MaterialTheme.padding.medium)) { + var selected by remember { mutableStateOf(readingMode) } + + ModeSelectionDialog( + onUseDefault = { onChangeReadingMode(ReadingMode.DEFAULT) }.takeIf { readingMode != ReadingMode.DEFAULT }, + onApply = { onChangeReadingMode(selected) }, + ) { SettingsIconGrid(R.string.pref_category_reading_mode) { - items(ReadingMode.entries) { mode -> + items(ReadingModesWithoutDefault) { mode -> IconToggleButton( - checked = mode == readingMode, + checked = mode == selected, onCheckedChange = { - onChangeReadingMode(mode) + selected = mode }, modifier = Modifier.fillMaxWidth(), imageVector = ImageVector.vectorResource(mode.iconRes), @@ -73,10 +80,17 @@ private fun DialogContent( private fun DialogContentPreview() { TachiyomiTheme { Surface { - DialogContent( - readingMode = ReadingMode.DEFAULT, - onChangeReadingMode = {}, - ) + Column { + DialogContent( + readingMode = ReadingMode.DEFAULT, + onChangeReadingMode = {}, + ) + + DialogContent( + readingMode = ReadingMode.LEFT_TO_RIGHT, + onChangeReadingMode = {}, + ) + } } } } diff --git a/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt b/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt index de3d0131f6..aff4c8c3fa 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt @@ -23,6 +23,7 @@ import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBarActions +import eu.kanade.presentation.reader.components.ChapterNavigator import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode diff --git a/app/src/main/java/eu/kanade/presentation/reader/appbars/ChapterNavigator.kt b/app/src/main/java/eu/kanade/presentation/reader/components/ChapterNavigator.kt similarity index 99% rename from app/src/main/java/eu/kanade/presentation/reader/appbars/ChapterNavigator.kt rename to app/src/main/java/eu/kanade/presentation/reader/components/ChapterNavigator.kt index ede1ae3328..a2a3a5c782 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/appbars/ChapterNavigator.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/components/ChapterNavigator.kt @@ -1,4 +1,4 @@ -package eu.kanade.presentation.reader.appbars +package eu.kanade.presentation.reader.components import androidx.compose.foundation.background import androidx.compose.foundation.interaction.MutableInteractionSource diff --git a/app/src/main/java/eu/kanade/presentation/reader/components/ModeSelectionDialog.kt b/app/src/main/java/eu/kanade/presentation/reader/components/ModeSelectionDialog.kt new file mode 100644 index 0000000000..045155b692 --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/reader/components/ModeSelectionDialog.kt @@ -0,0 +1,89 @@ +package eu.kanade.presentation.reader.components + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Check +import androidx.compose.material3.FilledTonalButton +import androidx.compose.material3.Icon +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.PreviewLightDark +import androidx.compose.ui.unit.dp +import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.tachiyomi.R +import tachiyomi.presentation.core.components.SettingsItemsPaddings + +@Composable +fun ModeSelectionDialog( + onApply: () -> Unit, + onUseDefault: (() -> Unit)? = null, + content: @Composable () -> Unit, +) { + Box(modifier = Modifier.padding(vertical = 16.dp)) { + Column { + content() + + Row( + modifier = Modifier.padding( + horizontal = SettingsItemsPaddings.Horizontal, + ), + ) { + onUseDefault?.let { + OutlinedButton(onClick = it) { + Text(text = stringResource(R.string.action_revert_to_default)) + } + } + + Spacer(modifier = Modifier.weight(1f)) + + FilledTonalButton( + onClick = onApply, + ) { + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Icon( + imageVector = Icons.Outlined.Check, + contentDescription = null, + ) + Text(text = stringResource(R.string.action_apply)) + } + } + } + } + } +} + +@PreviewLightDark +@Composable +private fun Preview() { + TachiyomiTheme { + Surface { + Column { + ModeSelectionDialog( + onApply = {}, + onUseDefault = {}, + ) { + Text("Dummy content") + } + + ModeSelectionDialog( + onApply = {}, + ) { + Text("Dummy content without default") + } + } + } + } +} diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index b15ee64e63..0a9c92a558 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -128,6 +128,7 @@ Disable Pin Unpin + Apply Cancel OK Cancel all @@ -147,6 +148,7 @@ Share Save Reset + Revert to default Undo Close