From 34fc95a1897f9d04d90441593ca464de153b87fe Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Tue, 1 Aug 2023 12:44:54 +0200 Subject: [PATCH 1/6] build: upgrade accompansit --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d3cf5a0..bc6346c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,7 +12,7 @@ composeActivity = "1.8.0-alpha06" compose = "1.6.0-alpha02" composeCompiler = "1.5.1" composeMaterial3 = "1.2.0-alpha04" -accompanist = "0.31.5-beta" +accompanist = "0.31.6-rc" #AutoFitTextView autofittextview = "0.2.1" #exp4j From 6f5673d9130d019039f1da9490b5e6bf133c3429 Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Wed, 23 Aug 2023 09:44:51 +0200 Subject: [PATCH 2/6] upgrade to latest commons implementations --- .../calculator/activities/SettingsActivity.kt | 10 +- .../compose/screens/SettingsScreen.kt | 230 ++++++------------ gradle/libs.versions.toml | 8 +- 3 files changed, 76 insertions(+), 172 deletions(-) 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 4d92022..ba6c46c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt @@ -6,7 +6,6 @@ import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity import androidx.compose.runtime.* -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.core.view.WindowCompat import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -49,16 +48,10 @@ class SettingsActivity : AppCompatActivity() { val lockedCustomizeColorText by remember(isOrWasThankYouInstalled) { derivedStateOf { if (isOrWasThankYouInstalled) null else getCustomizeColorsString() } } - val statusBarColor = onEventValue { context.getColoredMaterialStatusBarColor() } - val contrastColor by remember(statusBarColor) { - derivedStateOf { statusBarColor.getContrastColor() } - } - SettingsScreen( goBack = ::finish, customizeColors = ::handleCustomizeColorsClick, customizeWidgetColors = ::setupCustomizeWidgetColors, - topBarsScrolledContainerColor = Color(statusBarColor), preventPhoneFromSleeping = preventPhoneFromSleeping, onPreventPhoneFromSleeping = preferences::preventPhoneFromSleeping::set, vibrateOnButtonPressFlow = vibrateOnButtonPressFlow, @@ -80,8 +73,7 @@ class SettingsActivity : AppCompatActivity() { applicationContext.calculatorDB.deleteHistory() } }, - lockedCustomizeColorText = lockedCustomizeColorText, - topBarsContentColor = Color(contrastColor) + lockedCustomizeColorText = lockedCustomizeColorText ) } } 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 906c640..6fa79a6 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,47 +1,29 @@ package com.simplemobiletools.calculator.compose.screens -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.foundation.verticalScroll -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowBack -import androidx.compose.material.ripple.rememberRipple import androidx.compose.material3.* import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.lerp -import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import com.google.accompanist.systemuicontroller.rememberSystemUiController 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.scaffold.SettingsScaffold import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.divider_grey -import com.simplemobiletools.commons.compose.theme.isNotLitWell -import com.simplemobiletools.commons.compose.theme.isSurfaceLitWell import com.simplemobiletools.commons.helpers.isTiramisuPlus import java.util.Locale @Composable -fun SettingsScreen( +internal fun SettingsScreen( goBack: () -> Unit, customizeColors: () -> Unit, customizeWidgetColors: () -> Unit, - topBarsScrolledContainerColor: Color, - nonScrolledTextColor: Color = if (isSurfaceLitWell()) Color.Black else Color.White, preventPhoneFromSleeping: Boolean, onPreventPhoneFromSleeping: (Boolean) -> Unit, vibrateOnButtonPressFlow: Boolean, @@ -54,148 +36,79 @@ fun SettingsScreen( onSetupLanguagePress: () -> Unit, useCommaAsDecimalMarkFlow: Boolean, onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit, - lockedCustomizeColorText: String?, - topBarsContentColor: Color + lockedCustomizeColorText: String? ) { - val systemUiController = rememberSystemUiController() val displayLanguage = remember { Locale.getDefault().displayLanguage } - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) - val colorTransitionFraction = scrollBehavior.state.overlappedFraction - val fraction = if (colorTransitionFraction > 0.01f) 1f else 0f - val scrolledColor = lerp( - start = nonScrolledTextColor, - stop = topBarsContentColor, - fraction = fraction - ) - SideEffect { - systemUiController.setStatusBarColor(Color.Transparent, darkIcons = scrolledColor.isNotLitWell()) - } val startingPadding = Modifier.padding(horizontal = 4.dp) - val navigationIconInteractionSource = remember { MutableInteractionSource() } - Scaffold( - modifier = Modifier - .fillMaxSize() - .nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - TopAppBar( - title = { - Text( - text = stringResource(id = R.string.settings), - modifier = Modifier - .padding(start = 8.dp) - .fillMaxWidth(), - color = scrolledColor - ) - }, - navigationIcon = { - Box( - Modifier - .padding(start = 8.dp) - .clip(RoundedCornerShape(50)) - .clickable( - navigationIconInteractionSource, rememberRipple( - color = MaterialTheme.colorScheme.onSurface, - bounded = true - ) - ) { goBack() } - ) { - Icon( - imageVector = Icons.Filled.ArrowBack, contentDescription = stringResource(id = R.string.back), - tint = scrolledColor, - modifier = Modifier.padding(5.dp) - ) - } - - }, - scrollBehavior = scrollBehavior, - colors = TopAppBarDefaults.largeTopAppBarColors( - scrolledContainerColor = topBarsScrolledContainerColor, - containerColor = if (colorTransitionFraction == 1f) topBarsContentColor else MaterialTheme.colorScheme.surface, - navigationIconContentColor = if (colorTransitionFraction == 1f) topBarsContentColor else MaterialTheme.colorScheme.surface - ), + SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) { paddingValues -> + SettingsGroup(title = { + SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization), modifier = startingPadding) + }) { + SettingsPreferenceComponent( + modifier = Modifier + .padding(bottom = 12.dp, top = 8.dp) + .then(startingPadding), + preferenceTitle = stringResource(id = R.string.customize_colors), + doOnPreferenceClick = customizeColors, + isPreferenceEnabled = isOrWasThankYouInstalled, + preferenceSummary = lockedCustomizeColorText + ) + SettingsPreferenceComponent( + modifier = Modifier + .padding(bottom = 12.dp) + .then(startingPadding), + preferenceTitle = stringResource(id = R.string.customize_widget_colors), + doOnPreferenceClick = customizeWidgetColors ) } - ) { paddingValues -> - Box( - modifier = Modifier - .fillMaxSize() - .padding(paddingValues) - .background(MaterialTheme.colorScheme.surface) - ) { - Column( - Modifier - .matchParentSize() - .verticalScroll(rememberScrollState()), - ) { - SettingsGroup(title = { - SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization), modifier = startingPadding) - }) { - SettingsPreferenceComponent( - modifier = Modifier - .padding(bottom = 12.dp, top = 8.dp) - .then(startingPadding), - preferenceTitle = stringResource(id = R.string.customize_colors), - doOnPreferenceClick = customizeColors, - isPreferenceEnabled = isOrWasThankYouInstalled, - preferenceSummary = lockedCustomizeColorText - ) - SettingsPreferenceComponent( - modifier = Modifier - .padding(bottom = 12.dp) - .then(startingPadding), - preferenceTitle = stringResource(id = R.string.customize_widget_colors), - doOnPreferenceClick = customizeWidgetColors - ) - } - HorizontalDivider(color = divider_grey) - SettingsGroup(title = { - SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings), modifier = startingPadding) - }) { - if (!isOrWasThankYouInstalled) { - SettingsPreferenceComponent( - preferenceTitle = stringResource(id = R.string.purchase_simple_thank_you), - doOnPreferenceClick = onThankYou, - modifier = startingPadding, - ) - } - if (isUseEnglishEnabled) { - SettingsCheckBoxComponent( - title = stringResource(id = R.string.use_english_language), - initialValue = isUseEnglishChecked, - onChange = onUseEnglishPress, - modifier = startingPadding, - ) - } - if (isTiramisuPlus()) { - SettingsPreferenceComponent( - preferenceTitle = stringResource(id = R.string.language), - preferenceSummary = displayLanguage, - doOnPreferenceClick = onSetupLanguagePress, - preferenceSummaryColor = MaterialTheme.colorScheme.onSurface, - modifier = startingPadding, - ) - } - SettingsCheckBoxComponent( - title = stringResource(id = R.string.vibrate_on_button_press), - initialValue = vibrateOnButtonPressFlow, - onChange = onVibrateOnButtonPressFlow, - modifier = startingPadding, - ) - SettingsCheckBoxComponent( - title = stringResource(id = R.string.prevent_phone_from_sleeping), - initialValue = preventPhoneFromSleeping, - onChange = onPreventPhoneFromSleeping, - modifier = startingPadding, - ) - SettingsCheckBoxComponent( - title = stringResource(id = com.simplemobiletools.calculator.R.string.use_comma_as_decimal_mark), - initialValue = useCommaAsDecimalMarkFlow, - onChange = onUseCommaAsDecimalMarkFlow, - modifier = startingPadding, - ) - } + HorizontalDivider(color = divider_grey) + SettingsGroup(title = { + SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings), modifier = startingPadding) + }) { + if (!isOrWasThankYouInstalled) { + SettingsPreferenceComponent( + preferenceTitle = stringResource(id = R.string.purchase_simple_thank_you), + doOnPreferenceClick = onThankYou, + modifier = startingPadding, + ) } + if (isUseEnglishEnabled) { + SettingsCheckBoxComponent( + title = stringResource(id = R.string.use_english_language), + initialValue = isUseEnglishChecked, + onChange = onUseEnglishPress, + modifier = startingPadding, + ) + } + if (isTiramisuPlus()) { + SettingsPreferenceComponent( + preferenceTitle = stringResource(id = R.string.language), + preferenceSummary = displayLanguage, + doOnPreferenceClick = onSetupLanguagePress, + preferenceSummaryColor = MaterialTheme.colorScheme.onSurface, + modifier = startingPadding, + ) + } + SettingsCheckBoxComponent( + title = stringResource(id = R.string.vibrate_on_button_press), + initialValue = vibrateOnButtonPressFlow, + onChange = onVibrateOnButtonPressFlow, + modifier = startingPadding, + ) + SettingsCheckBoxComponent( + title = stringResource(id = R.string.prevent_phone_from_sleeping), + initialValue = preventPhoneFromSleeping, + onChange = onPreventPhoneFromSleeping, + modifier = startingPadding, + ) + SettingsCheckBoxComponent( + title = stringResource(id = com.simplemobiletools.calculator.R.string.use_comma_as_decimal_mark), + initialValue = useCommaAsDecimalMarkFlow, + onChange = onUseCommaAsDecimalMarkFlow, + modifier = startingPadding, + ) } + Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding())) } } @@ -207,8 +120,6 @@ private fun SettingsScreenPreview() { goBack = {}, customizeColors = {}, customizeWidgetColors = {}, - topBarsScrolledContainerColor = MaterialTheme.colorScheme.primary, - nonScrolledTextColor = Color.White, preventPhoneFromSleeping = false, onPreventPhoneFromSleeping = {}, vibrateOnButtonPressFlow = false, @@ -219,8 +130,9 @@ private fun SettingsScreenPreview() { isUseEnglishChecked = false, onUseEnglishPress = {}, onSetupLanguagePress = {}, - useCommaAsDecimalMarkFlow = false, onUseCommaAsDecimalMarkFlow = {}, lockedCustomizeColorText = null, - topBarsContentColor = MaterialTheme.colorScheme.onPrimary + useCommaAsDecimalMarkFlow = false, + onUseCommaAsDecimalMarkFlow = {}, + lockedCustomizeColorText = null ) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 61dc401..b6fd03d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,10 +9,10 @@ androidx-customViewPooling = "1.0.0" androidx-lifecycle = "2.7.0-alpha01" #Compose composeActivity = "1.8.0-alpha06" -compose = "1.6.0-alpha02" +compose = "1.6.0-alpha03" composeCompiler = "1.5.1" -composeMaterial3 = "1.2.0-alpha04" -accompanist = "0.31.6-rc" +composeMaterial3 = "1.2.0-alpha05" +accompanist = "0.33.0-alpha" #AutoFitTextView autofittextview = "0.2.1" #exp4j @@ -22,7 +22,7 @@ room = "2.5.2" #Simple tools simple-commons = "b80b717ad3" #Gradle -gradlePlugins-agp = "8.1.0" +gradlePlugins-agp = "8.1.1" #build app-build-compileSDKVersion = "34" app-build-targetSDK = "34" From 796921fa518ece3bd74150f86c4a12423813f339 Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Wed, 23 Aug 2023 10:44:44 +0200 Subject: [PATCH 3/6] upgrade to latest commons implementations and remove unnecessary code --- .../calculator/activities/SettingsActivity.kt | 2 + .../compose/screens/SettingsScreen.kt | 24 ++-- .../settings/SettingsCheckBoxComponent.kt | 103 ------------------ .../compose/settings/SettingsGroup.kt | 63 ----------- .../settings/SettingsPreferenceComponent.kt | 75 ------------- .../settings/SettingsTitleTextComponent.kt | 36 ------ gradle/libs.versions.toml | 2 +- 7 files changed, 16 insertions(+), 289 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsCheckBoxComponent.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsGroup.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsPreferenceComponent.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/calculator/compose/settings/SettingsTitleTextComponent.kt 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 From 3323eb0613590f64c1ec32f437585a4591fc65e6 Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Wed, 23 Aug 2023 11:01:39 +0200 Subject: [PATCH 4/6] remove from nested folder --- .../simplemobiletools/calculator/activities/SettingsActivity.kt | 2 +- .../calculator/compose/{screens => }/SettingsScreen.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/src/main/kotlin/com/simplemobiletools/calculator/compose/{screens => }/SettingsScreen.kt (99%) 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 cf40818..01d0f72 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt @@ -9,7 +9,7 @@ import androidx.compose.runtime.* import androidx.compose.ui.platform.LocalContext import androidx.core.view.WindowCompat import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.simplemobiletools.calculator.compose.screens.SettingsScreen +import com.simplemobiletools.calculator.compose.SettingsScreen import com.simplemobiletools.calculator.extensions.* import com.simplemobiletools.commons.activities.CustomizationActivity import com.simplemobiletools.commons.compose.extensions.TransparentSystemBars diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/screens/SettingsScreen.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt similarity index 99% rename from app/src/main/kotlin/com/simplemobiletools/calculator/compose/screens/SettingsScreen.kt rename to app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt index dfa7973..832b9ee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/screens/SettingsScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt @@ -1,4 +1,4 @@ -package com.simplemobiletools.calculator.compose.screens +package com.simplemobiletools.calculator.compose import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding From 85c31f897fc0915751c04c3b1e8192f93e850f3c Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Wed, 23 Aug 2023 11:02:52 +0200 Subject: [PATCH 5/6] fix: add same vertical paddings --- .../simplemobiletools/calculator/compose/SettingsScreen.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt index 832b9ee..20e0c13 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt @@ -47,7 +47,7 @@ internal fun SettingsScreen( }) { SettingsPreferenceComponent( modifier = Modifier - .padding(bottom = 12.dp, top = 8.dp) + .padding(vertical = 12.dp) .then(startingPadding), preferenceTitle = stringResource(id = R.string.customize_colors), doOnPreferenceClick = customizeColors, @@ -56,7 +56,7 @@ internal fun SettingsScreen( ) SettingsPreferenceComponent( modifier = Modifier - .padding(bottom = 12.dp) + .padding(vertical = 12.dp) .then(startingPadding), preferenceTitle = stringResource(id = R.string.customize_widget_colors), doOnPreferenceClick = customizeWidgetColors From b9d6d483eab0c5124330c4d988c7ec4facfbc22a Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Wed, 23 Aug 2023 11:33:25 +0200 Subject: [PATCH 6/6] fix: remove paddings as they're coming from commons now --- .../calculator/compose/SettingsScreen.kt | 17 ++--------------- gradle/libs.versions.toml | 2 +- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt index 20e0c13..f4f7357 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/SettingsScreen.kt @@ -40,37 +40,29 @@ internal fun SettingsScreen( lockedCustomizeColorText: String?, displayLanguage: String ) { - 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) + SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization)) }) { SettingsPreferenceComponent( - modifier = Modifier - .padding(vertical = 12.dp) - .then(startingPadding), preferenceTitle = stringResource(id = R.string.customize_colors), doOnPreferenceClick = customizeColors, isPreferenceEnabled = isOrWasThankYouInstalled, preferenceSummary = lockedCustomizeColorText ) SettingsPreferenceComponent( - modifier = Modifier - .padding(vertical = 12.dp) - .then(startingPadding), preferenceTitle = stringResource(id = R.string.customize_widget_colors), doOnPreferenceClick = customizeWidgetColors ) } HorizontalDivider(color = divider_grey) SettingsGroup(title = { - SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings), modifier = startingPadding) + SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings)) }) { if (!isOrWasThankYouInstalled) { SettingsPreferenceComponent( preferenceTitle = stringResource(id = R.string.purchase_simple_thank_you), doOnPreferenceClick = onThankYou, - modifier = startingPadding, ) } if (isUseEnglishEnabled) { @@ -78,7 +70,6 @@ internal fun SettingsScreen( title = stringResource(id = R.string.use_english_language), initialValue = isUseEnglishChecked, onChange = onUseEnglishPress, - modifier = startingPadding, ) } if (isTiramisuPlus()) { @@ -87,26 +78,22 @@ internal fun SettingsScreen( preferenceSummary = displayLanguage, doOnPreferenceClick = onSetupLanguagePress, preferenceSummaryColor = MaterialTheme.colorScheme.onSurface, - modifier = startingPadding, ) } SettingsCheckBoxComponent( title = stringResource(id = R.string.vibrate_on_button_press), initialValue = vibrateOnButtonPressFlow, onChange = onVibrateOnButtonPressFlow, - modifier = startingPadding, ) SettingsCheckBoxComponent( title = stringResource(id = R.string.prevent_phone_from_sleeping), initialValue = preventPhoneFromSleeping, onChange = onPreventPhoneFromSleeping, - modifier = startingPadding, ) SettingsCheckBoxComponent( title = stringResource(id = com.simplemobiletools.calculator.R.string.use_comma_as_decimal_mark), initialValue = useCommaAsDecimalMarkFlow, onChange = onUseCommaAsDecimalMarkFlow, - modifier = startingPadding, ) } Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding())) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f09738c..8019d40 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 = "c3d56ea0d0" +simple-commons = "565200547d" #Gradle gradlePlugins-agp = "8.1.1" #build