Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ package com.orange.ouds.app.ui

import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -58,12 +60,14 @@ private fun ChangeThemeSettingsDialogContent(themeState: ThemeState, onThemeSett
getSupportedThemeSettings(themeState.currentTheme).forEach { themeSetting ->
OudsSwitchItem(
checked = when (themeSetting) {
ThemeSetting.RoundedCornerAlertMessages -> themeSettings.roundedCornerAlertMessages.orElse { false }
ThemeSetting.RoundedCornerButtons -> themeSettings.roundedCornerButtons.orElse { false }
ThemeSetting.RoundedCornerTextInputs -> themeSettings.roundedCornerTextInputs.orElse { false }
},
label = stringResource(themeSetting.titleResId),
onCheckedChange = { checked ->
themeSettings = when (themeSetting) {
ThemeSetting.RoundedCornerAlertMessages -> themeSettings.copy(roundedCornerAlertMessages = checked)
ThemeSetting.RoundedCornerButtons -> themeSettings.copy(roundedCornerButtons = checked)
ThemeSetting.RoundedCornerTextInputs -> themeSettings.copy(roundedCornerTextInputs = checked)
}
Expand All @@ -72,21 +76,22 @@ private fun ChangeThemeSettingsDialogContent(themeState: ThemeState, onThemeSett
)
}

Row(
Column(
modifier = Modifier
.padding(horizontal = OudsTheme.grids.margin, vertical = OudsTheme.spaces.fixed.large)
.align(Alignment.End),
horizontalArrangement = Arrangement.spacedBy(OudsTheme.spaces.fixed.extraSmall)
.padding(horizontal = OudsTheme.grids.margin, vertical = OudsTheme.spaces.fixed.large),
verticalArrangement = Arrangement.spacedBy(OudsTheme.spaces.fixed.extraSmall)
) {
OudsButton(
modifier = Modifier.fillMaxWidth(),
label = stringResource(R.string.app_themeSettingsDialog_apply_label),
onClick = { onThemeSettingsChange(themeSettings) }
)
OudsButton(
modifier = Modifier.fillMaxWidth(),
label = stringResource(R.string.app_themeSettingsDialog_cancel_label),
appearance = OudsButtonAppearance.Minimal,
onClick = { onThemeSettingsChange(themeState.currentTheme.settings) }
)
OudsButton(
label = stringResource(R.string.app_themeSettingsDialog_apply_label),
onClick = { onThemeSettingsChange(themeSettings) }
)
}
}
}
Expand All @@ -95,6 +100,7 @@ private fun getSupportedThemeSettings(theme: OudsThemeContract): List<ThemeSetti
return ThemeSetting.entries.filter { themeSetting ->
with(theme.settings) {
when (themeSetting) {
ThemeSetting.RoundedCornerAlertMessages -> roundedCornerAlertMessages != null
ThemeSetting.RoundedCornerButtons -> roundedCornerButtons != null
ThemeSetting.RoundedCornerTextInputs -> roundedCornerTextInputs != null
}
Expand All @@ -111,11 +117,12 @@ object ChangeThemeSettingsDialog {

private enum class ThemeSetting {

RoundedCornerButtons, RoundedCornerTextInputs;
RoundedCornerAlertMessages, RoundedCornerButtons, RoundedCornerTextInputs;

val titleResId: Int
@StringRes
get() = when (this) {
RoundedCornerAlertMessages -> R.string.app_themeSettingsDialog_roundedCornerAlertMessages_label
RoundedCornerButtons -> R.string.app_themeSettingsDialog_roundedCornerButtons_label
RoundedCornerTextInputs -> R.string.app_themeSettingsDialog_roundedCornerTextInputs_label
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/orange/ouds/app/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MainViewModel @Inject constructor(private val dataStoreService: DataStoreS

companion object {
private const val USER_THEME_NAME_KEY = "userThemeName"
private const val USER_THEME_SETTINGS_ROUNDED_CORNER_ALERT_MESSAGES_KEY = "userThemeSettingsRoundedCornerAlertMessages"
private const val USER_THEME_SETTINGS_ROUNDED_CORNER_BUTTONS_KEY = "userThemeSettingsRoundedCornerButtons"
private const val USER_THEME_SETTINGS_ROUNDED_CORNER_TEXT_INPUTS_KEY = "userThemeSettingsRoundedCornerTextInputs"
}
Expand All @@ -38,12 +39,14 @@ class MainViewModel @Inject constructor(private val dataStoreService: DataStoreS
}

fun storeUserThemeSettings(themeSettings: OudsThemeSettings) = runBlocking {
dataStoreService.putBoolean(USER_THEME_SETTINGS_ROUNDED_CORNER_ALERT_MESSAGES_KEY, themeSettings.roundedCornerAlertMessages)
dataStoreService.putBoolean(USER_THEME_SETTINGS_ROUNDED_CORNER_BUTTONS_KEY, themeSettings.roundedCornerButtons)
dataStoreService.putBoolean(USER_THEME_SETTINGS_ROUNDED_CORNER_TEXT_INPUTS_KEY, themeSettings.roundedCornerTextInputs)
}

fun getUserThemeSettings(): OudsThemeSettings? = runBlocking {
OudsThemeSettings(
roundedCornerAlertMessages = dataStoreService.getBoolean(USER_THEME_SETTINGS_ROUNDED_CORNER_ALERT_MESSAGES_KEY),
roundedCornerButtons = dataStoreService.getBoolean(USER_THEME_SETTINGS_ROUNDED_CORNER_BUTTONS_KEY),
roundedCornerTextInputs = dataStoreService.getBoolean(USER_THEME_SETTINGS_ROUNDED_CORNER_TEXT_INPUTS_KEY)
)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/orange/ouds/app/ui/ThemeState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ class ThemeState(
when (name) {
ORANGE_THEME_NAME -> OrangeTheme(
orangeFontFamily = OrangeFontFamily(OrangeHelveticaNeueLatin.Downloadable, OrangeHelveticaNeueArabic.Downloadable),
roundedCornerAlertMessages = roundedCornerAlertMessages.orElse { false },
roundedCornerButtons = roundedCornerButtons.orElse { false },
roundedCornerTextInputs = roundedCornerTextInputs.orElse { false }
)
ORANGE_COMPACT_THEME_NAME -> OrangeCompactTheme(
orangeFontFamily = OrangeFontFamily(OrangeHelveticaNeueLatin.Downloadable, OrangeHelveticaNeueArabic.Downloadable),
roundedCornerAlertMessages = roundedCornerAlertMessages.orElse { false },
roundedCornerButtons = roundedCornerButtons.orElse { false },
roundedCornerTextInputs = roundedCornerTextInputs.orElse { false }
)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<string name="app_themeSettingsDialog_apply_label">تطبيق</string>
<string name="app_themeSettingsDialog_cancel_label">إلغاء</string>
<string name="app_themeSettingsDialog_label">تغيير إعدادات السمة</string>
<string name="app_themeSettingsDialog_roundedCornerAlertMessages_label">رسائل التنبيه بزوايا مستديرة</string>
<string name="app_themeSettingsDialog_roundedCornerButtons_label">زر بزوايا مستديرة</string>
<string name="app_themeSettingsDialog_roundedCornerTextInputs_label">حقول إدخال نص بزوايا مستديرة</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<string name="app_themeSettingsDialog_apply_label">Appliquer</string>
<string name="app_themeSettingsDialog_cancel_label">Annuler</string>
<string name="app_themeSettingsDialog_label">Changer les réglages du thème</string>
<string name="app_themeSettingsDialog_roundedCornerAlertMessages_label">Messages d\'alerte avec coins arrondis</string>
<string name="app_themeSettingsDialog_roundedCornerButtons_label">Buttons avec coins arrondis</string>
<string name="app_themeSettingsDialog_roundedCornerTextInputs_label">Text Inputs avec coins arrondis</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<string name="app_themeSettingsDialog_apply_label">Apply</string>
<string name="app_themeSettingsDialog_cancel_label">Cancel</string>
<string name="app_themeSettingsDialog_label">Change theme settings</string>
<string name="app_themeSettingsDialog_roundedCornerAlertMessages_label">Rounded corner alert messages</string>
<string name="app_themeSettingsDialog_roundedCornerButtons_label">Rounded corner button</string>
<string name="app_themeSettingsDialog_roundedCornerTextInputs_label">Rounded corner text inputs</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ const val ORANGE_THEME_NAME = "Orange"
* @param orangeFontFamily The Helvetica Neue font family to use for the Orange theme.
* If an [OrangeBundledFontFamily] is used, the resource identifiers should reference Helvetica Neue font files.
* If an [OrangeDownloadableFontFamily] is used, the [OrangeFontFamily.preloadDownloadableFontFamilies] method should be called to download the Helvetica Neue font files through the Android Downloadable Fonts feature.
* @param roundedCornerButtons Whether or not buttons have rounded corners.
* @param roundedCornerTextInputs Whether or not text inputs have rounded corners.
* @param roundedCornerAlertMessages Whether or not alert messages have rounded corners.
* @param roundedCornerButtons Whether buttons have rounded corners.
* @param roundedCornerTextInputs Whether text inputs have rounded corners.
* @param roundedCornerAlertMessages Whether alert messages have rounded corners.
*/
open class OrangeTheme(
private val orangeFontFamily: OrangeFontFamily,
Expand All @@ -131,8 +131,8 @@ open class OrangeTheme(
/**
* Creates a new Orange theme.
*
* @param roundedCornerButtons Whether or not buttons have rounded corners.
* @param roundedCornerTextInputs Whether or not text inputs have rounded corners.
* @param roundedCornerButtons Whether buttons have rounded corners.
* @param roundedCornerTextInputs Whether text inputs have rounded corners.
*/
@Deprecated(
"Use constructor with orangeFontFamily parameter instead.",
Expand Down
Loading