diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt index ba6c46c..cf40818 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt @@ -48,7 +48,9 @@ class SettingsActivity : AppCompatActivity() { val lockedCustomizeColorText by remember(isOrWasThankYouInstalled) { derivedStateOf { if (isOrWasThankYouInstalled) null else getCustomizeColorsString() } } + val displayLanguage = remember { Locale.getDefault().displayLanguage } SettingsScreen( + displayLanguage = displayLanguage, goBack = ::finish, customizeColors = ::handleCustomizeColorsClick, customizeWidgetColors = ::setupCustomizeWidgetColors, diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/screens/SettingsScreen.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/screens/SettingsScreen.kt index 6fa79a6..dfa7973 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/screens/SettingsScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/screens/SettingsScreen.kt @@ -1,23 +1,24 @@ package com.simplemobiletools.calculator.compose.screens -import androidx.compose.foundation.layout.* -import androidx.compose.material3.* +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import com.simplemobiletools.calculator.compose.settings.SettingsCheckBoxComponent -import com.simplemobiletools.calculator.compose.settings.SettingsGroup -import com.simplemobiletools.calculator.compose.settings.SettingsPreferenceComponent -import com.simplemobiletools.calculator.compose.settings.SettingsTitleTextComponent import com.simplemobiletools.commons.R import com.simplemobiletools.commons.compose.extensions.MyDevices +import com.simplemobiletools.commons.compose.settings.SettingsCheckBoxComponent +import com.simplemobiletools.commons.compose.settings.SettingsGroup +import com.simplemobiletools.commons.compose.settings.SettingsPreferenceComponent +import com.simplemobiletools.commons.compose.settings.SettingsTitleTextComponent import com.simplemobiletools.commons.compose.settings.scaffold.SettingsScaffold import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.divider_grey import com.simplemobiletools.commons.helpers.isTiramisuPlus -import java.util.Locale @Composable internal fun SettingsScreen( @@ -36,10 +37,10 @@ internal fun SettingsScreen( onSetupLanguagePress: () -> Unit, useCommaAsDecimalMarkFlow: Boolean, onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit, - lockedCustomizeColorText: String? + lockedCustomizeColorText: String?, + displayLanguage: String ) { - val displayLanguage = remember { Locale.getDefault().displayLanguage } - val startingPadding = Modifier.padding(horizontal = 4.dp) + val startingPadding = remember { Modifier.padding(horizontal = 4.dp) } SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) { paddingValues -> SettingsGroup(title = { SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization), modifier = startingPadding) @@ -132,7 +133,8 @@ private fun SettingsScreenPreview() { onSetupLanguagePress = {}, useCommaAsDecimalMarkFlow = false, onUseCommaAsDecimalMarkFlow = {}, - lockedCustomizeColorText = null + lockedCustomizeColorText = null, + displayLanguage = "English" ) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsCheckBoxComponent.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsCheckBoxComponent.kt deleted file mode 100644 index 35a5652..0000000 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsCheckBoxComponent.kt +++ /dev/null @@ -1,103 +0,0 @@ -package com.simplemobiletools.calculator.compose.settings - -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.foundation.LocalIndication -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource -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.material.ripple.LocalRippleTheme -import androidx.compose.material3.Checkbox -import androidx.compose.material3.CheckboxDefaults -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.dimensionResource -import androidx.compose.ui.unit.dp -import com.simplemobiletools.commons.R -import com.simplemobiletools.commons.compose.extensions.MyDevices -import com.simplemobiletools.commons.compose.extensions.NoRippleTheme -import com.simplemobiletools.commons.compose.theme.AppThemeSurface -import com.simplemobiletools.commons.compose.theme.preferenceSummaryColor -import com.simplemobiletools.commons.compose.theme.preferenceTitleColor - -@Composable -fun SettingsCheckBoxComponent( - modifier: Modifier = Modifier, - title: String, - summary: String? = null, - initialValue: Boolean = false, - isPreferenceEnabled: Boolean = true, - onChange: ((Boolean) -> Unit)? = null, - checkboxColor: Color = MaterialTheme.colorScheme.primary -) { - val interactionSource = remember { MutableInteractionSource() } - val indication = LocalIndication.current - - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = modifier - .fillMaxWidth() - .clickable( - onClick = { onChange?.invoke(!initialValue) }, - interactionSource = interactionSource, - indication = indication - ) - .padding(horizontal = 16.dp, vertical = 6.dp), - ) { - Column( - modifier = Modifier.weight(1f) - ) { - Text( - modifier = Modifier - .fillMaxWidth() - .padding(end = 16.dp), - text = title, - color = preferenceTitleColor(isEnabled = isPreferenceEnabled), - fontSize = with(LocalDensity.current) { - dimensionResource(id = R.dimen.normal_text_size).toSp() - } - ) - AnimatedVisibility(visible = !summary.isNullOrBlank()) { - Text( - text = summary.toString(), - modifier = Modifier - .fillMaxWidth() - .padding(end = 16.dp), - color = preferenceSummaryColor(isEnabled = isPreferenceEnabled), - ) - } - } - CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) { - Checkbox( - checked = initialValue, - onCheckedChange = { onChange?.invoke(it) }, - enabled = isPreferenceEnabled, - colors = CheckboxDefaults.colors( - checkedColor = checkboxColor, - checkmarkColor = MaterialTheme.colorScheme.surface - ), - interactionSource = interactionSource - ) - } - } -} - -@MyDevices -@Composable -private fun SettingsCheckBoxComponentPreview() { - AppThemeSurface { - SettingsCheckBoxComponent( - title = "Some title", - summary = "Some summary", - ) - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsGroup.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsGroup.kt deleted file mode 100644 index c1fa77d..0000000 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsGroup.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.simplemobiletools.calculator.compose.settings - -import androidx.compose.foundation.layout.* -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.ProvideTextStyle -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import com.simplemobiletools.commons.compose.extensions.MyDevices - -@Composable -fun SettingsGroup( - modifier: Modifier = Modifier, - title: @Composable (() -> Unit)? = null, - content: @Composable ColumnScope.() -> Unit, -) { - Column( - modifier = modifier.fillMaxWidth(), - ) { - if (title != null) { - SettingsGroupTitle(title = title) - } - content() - } -} - -@Composable -fun SettingsGroupTitle( - modifier: Modifier = Modifier, - title: @Composable () -> Unit -) { - Box( - modifier = modifier - .fillMaxWidth() - .padding(horizontal = 16.dp), - contentAlignment = Alignment.CenterStart - ) { - val primary = MaterialTheme.colorScheme.primary - val titleStyle = MaterialTheme.typography.headlineMedium.copy(color = primary) - ProvideTextStyle(value = titleStyle) { title() } - } -} - -@MyDevices -@Composable -private fun SettingsGroupPreview() { - MaterialTheme { - SettingsGroup( - title = { Text(text = "Title") } - ) { - Box( - modifier = Modifier - .height(64.dp) - .fillMaxWidth(), - contentAlignment = Alignment.Center, - ) { - Text(text = "Settings group") - } - } - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsPreferenceComponent.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsPreferenceComponent.kt deleted file mode 100644 index a01f425..0000000 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsPreferenceComponent.kt +++ /dev/null @@ -1,75 +0,0 @@ -package com.simplemobiletools.calculator.compose.settings - -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.foundation.combinedClickable -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.dimensionResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp -import com.simplemobiletools.commons.R -import com.simplemobiletools.commons.compose.extensions.MyDevices -import com.simplemobiletools.commons.compose.theme.AppThemeSurface -import com.simplemobiletools.commons.compose.theme.preferenceSummaryColor -import com.simplemobiletools.commons.compose.theme.preferenceTitleColor - -@Composable -fun SettingsPreferenceComponent( - modifier: Modifier = Modifier, - preferenceTitle: String, - preferenceSummary: String? = null, - isPreferenceEnabled: Boolean = true, - doOnPreferenceLongClick: (() -> Unit)? = null, - doOnPreferenceClick: (() -> Unit)? = null, - preferenceSummaryColor: Color = preferenceSummaryColor(isEnabled = isPreferenceEnabled) -) { - Column( - modifier = Modifier - .fillMaxWidth() - .combinedClickable( - enabled = isPreferenceEnabled, - onClick = { doOnPreferenceClick?.invoke() }, - onLongClick = { doOnPreferenceLongClick?.invoke() }, - ) - .padding(horizontal = 16.dp, vertical = 8.dp) - .then(modifier), - ) { - Text( - text = preferenceTitle, - modifier = Modifier.fillMaxWidth(), - color = preferenceTitleColor(isEnabled = isPreferenceEnabled), - fontSize = with(LocalDensity.current) { - dimensionResource(id = R.dimen.normal_text_size).toSp() - } - ) - AnimatedVisibility(visible = !preferenceSummary.isNullOrBlank()) { - Text( - text = preferenceSummary.toString(), - modifier = Modifier - .fillMaxWidth(), - color = preferenceSummaryColor.copy(alpha = 0.6f), - fontSize = with(LocalDensity.current) { - dimensionResource(id = R.dimen.normal_text_size).toSp() - } - ) - } - } -} - -@MyDevices -@Composable -private fun SettingsPreferencePreview() { - AppThemeSurface { - SettingsPreferenceComponent( - preferenceTitle = stringResource(id = R.string.language), - preferenceSummary = stringResource(id = R.string.translation_english), - isPreferenceEnabled = true, - ) - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsTitleTextComponent.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsTitleTextComponent.kt deleted file mode 100644 index 2caacae..0000000 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsTitleTextComponent.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.simplemobiletools.calculator.compose.settings - -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.dimensionResource -import androidx.compose.ui.unit.dp -import com.simplemobiletools.commons.compose.extensions.MyDevices -import com.simplemobiletools.commons.compose.theme.AppThemeSurface - -@Composable -fun SettingsTitleTextComponent( - modifier: Modifier = Modifier, - text: String, -) { - Box(modifier = Modifier.padding(top = 24.dp, bottom = 8.dp)) { - Text( - text = text.uppercase(), - modifier = modifier, - color = MaterialTheme.colorScheme.primary, - fontSize = with(LocalDensity.current) { - dimensionResource(id = com.simplemobiletools.commons.R.dimen.normal_text_size).toSp() - }, - ) - } -} - -@MyDevices -@Composable -private fun SettingsTitleTextComponentPreview() = AppThemeSurface { - SettingsTitleTextComponent(text = "Color customization") -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b6fd03d..f09738c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,7 +20,7 @@ exp4j = "0.4.8" #Room room = "2.5.2" #Simple tools -simple-commons = "b80b717ad3" +simple-commons = "c3d56ea0d0" #Gradle gradlePlugins-agp = "8.1.1" #build