From 6f5673d9130d019039f1da9490b5e6bf133c3429 Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Wed, 23 Aug 2023 09:44:51 +0200 Subject: [PATCH] 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"