upgrade to latest commons implementations
This commit is contained in:
parent
0dcfb1eb8a
commit
6f5673d913
3 changed files with 76 additions and 172 deletions
|
@ -6,7 +6,6 @@ import android.os.Bundle
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
@ -49,16 +48,10 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
val lockedCustomizeColorText by remember(isOrWasThankYouInstalled) {
|
val lockedCustomizeColorText by remember(isOrWasThankYouInstalled) {
|
||||||
derivedStateOf { if (isOrWasThankYouInstalled) null else getCustomizeColorsString() }
|
derivedStateOf { if (isOrWasThankYouInstalled) null else getCustomizeColorsString() }
|
||||||
}
|
}
|
||||||
val statusBarColor = onEventValue { context.getColoredMaterialStatusBarColor() }
|
|
||||||
val contrastColor by remember(statusBarColor) {
|
|
||||||
derivedStateOf { statusBarColor.getContrastColor() }
|
|
||||||
}
|
|
||||||
|
|
||||||
SettingsScreen(
|
SettingsScreen(
|
||||||
goBack = ::finish,
|
goBack = ::finish,
|
||||||
customizeColors = ::handleCustomizeColorsClick,
|
customizeColors = ::handleCustomizeColorsClick,
|
||||||
customizeWidgetColors = ::setupCustomizeWidgetColors,
|
customizeWidgetColors = ::setupCustomizeWidgetColors,
|
||||||
topBarsScrolledContainerColor = Color(statusBarColor),
|
|
||||||
preventPhoneFromSleeping = preventPhoneFromSleeping,
|
preventPhoneFromSleeping = preventPhoneFromSleeping,
|
||||||
onPreventPhoneFromSleeping = preferences::preventPhoneFromSleeping::set,
|
onPreventPhoneFromSleeping = preferences::preventPhoneFromSleeping::set,
|
||||||
vibrateOnButtonPressFlow = vibrateOnButtonPressFlow,
|
vibrateOnButtonPressFlow = vibrateOnButtonPressFlow,
|
||||||
|
@ -80,8 +73,7 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
applicationContext.calculatorDB.deleteHistory()
|
applicationContext.calculatorDB.deleteHistory()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
lockedCustomizeColorText = lockedCustomizeColorText,
|
lockedCustomizeColorText = lockedCustomizeColorText
|
||||||
topBarsContentColor = Color(contrastColor)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +1,29 @@
|
||||||
package com.simplemobiletools.calculator.compose.screens
|
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.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.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.SideEffect
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
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.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
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.SettingsCheckBoxComponent
|
||||||
import com.simplemobiletools.calculator.compose.settings.SettingsGroup
|
import com.simplemobiletools.calculator.compose.settings.SettingsGroup
|
||||||
import com.simplemobiletools.calculator.compose.settings.SettingsPreferenceComponent
|
import com.simplemobiletools.calculator.compose.settings.SettingsPreferenceComponent
|
||||||
import com.simplemobiletools.calculator.compose.settings.SettingsTitleTextComponent
|
import com.simplemobiletools.calculator.compose.settings.SettingsTitleTextComponent
|
||||||
import com.simplemobiletools.commons.R
|
import com.simplemobiletools.commons.R
|
||||||
import com.simplemobiletools.commons.compose.extensions.MyDevices
|
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.AppThemeSurface
|
||||||
import com.simplemobiletools.commons.compose.theme.divider_grey
|
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 com.simplemobiletools.commons.helpers.isTiramisuPlus
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsScreen(
|
internal fun SettingsScreen(
|
||||||
goBack: () -> Unit,
|
goBack: () -> Unit,
|
||||||
customizeColors: () -> Unit,
|
customizeColors: () -> Unit,
|
||||||
customizeWidgetColors: () -> Unit,
|
customizeWidgetColors: () -> Unit,
|
||||||
topBarsScrolledContainerColor: Color,
|
|
||||||
nonScrolledTextColor: Color = if (isSurfaceLitWell()) Color.Black else Color.White,
|
|
||||||
preventPhoneFromSleeping: Boolean,
|
preventPhoneFromSleeping: Boolean,
|
||||||
onPreventPhoneFromSleeping: (Boolean) -> Unit,
|
onPreventPhoneFromSleeping: (Boolean) -> Unit,
|
||||||
vibrateOnButtonPressFlow: Boolean,
|
vibrateOnButtonPressFlow: Boolean,
|
||||||
|
@ -54,148 +36,79 @@ fun SettingsScreen(
|
||||||
onSetupLanguagePress: () -> Unit,
|
onSetupLanguagePress: () -> Unit,
|
||||||
useCommaAsDecimalMarkFlow: Boolean,
|
useCommaAsDecimalMarkFlow: Boolean,
|
||||||
onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit,
|
onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit,
|
||||||
lockedCustomizeColorText: String?,
|
lockedCustomizeColorText: String?
|
||||||
topBarsContentColor: Color
|
|
||||||
) {
|
) {
|
||||||
val systemUiController = rememberSystemUiController()
|
|
||||||
val displayLanguage = remember { Locale.getDefault().displayLanguage }
|
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 startingPadding = Modifier.padding(horizontal = 4.dp)
|
||||||
val navigationIconInteractionSource = remember { MutableInteractionSource() }
|
SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) { paddingValues ->
|
||||||
Scaffold(
|
SettingsGroup(title = {
|
||||||
modifier = Modifier
|
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization), modifier = startingPadding)
|
||||||
.fillMaxSize()
|
}) {
|
||||||
.nestedScroll(scrollBehavior.nestedScrollConnection),
|
SettingsPreferenceComponent(
|
||||||
topBar = {
|
modifier = Modifier
|
||||||
TopAppBar(
|
.padding(bottom = 12.dp, top = 8.dp)
|
||||||
title = {
|
.then(startingPadding),
|
||||||
Text(
|
preferenceTitle = stringResource(id = R.string.customize_colors),
|
||||||
text = stringResource(id = R.string.settings),
|
doOnPreferenceClick = customizeColors,
|
||||||
modifier = Modifier
|
isPreferenceEnabled = isOrWasThankYouInstalled,
|
||||||
.padding(start = 8.dp)
|
preferenceSummary = lockedCustomizeColorText
|
||||||
.fillMaxWidth(),
|
)
|
||||||
color = scrolledColor
|
SettingsPreferenceComponent(
|
||||||
)
|
modifier = Modifier
|
||||||
},
|
.padding(bottom = 12.dp)
|
||||||
navigationIcon = {
|
.then(startingPadding),
|
||||||
Box(
|
preferenceTitle = stringResource(id = R.string.customize_widget_colors),
|
||||||
Modifier
|
doOnPreferenceClick = customizeWidgetColors
|
||||||
.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
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
HorizontalDivider(color = divider_grey)
|
||||||
Box(
|
SettingsGroup(title = {
|
||||||
modifier = Modifier
|
SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings), modifier = startingPadding)
|
||||||
.fillMaxSize()
|
}) {
|
||||||
.padding(paddingValues)
|
if (!isOrWasThankYouInstalled) {
|
||||||
.background(MaterialTheme.colorScheme.surface)
|
SettingsPreferenceComponent(
|
||||||
) {
|
preferenceTitle = stringResource(id = R.string.purchase_simple_thank_you),
|
||||||
Column(
|
doOnPreferenceClick = onThankYou,
|
||||||
Modifier
|
modifier = startingPadding,
|
||||||
.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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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 = {},
|
goBack = {},
|
||||||
customizeColors = {},
|
customizeColors = {},
|
||||||
customizeWidgetColors = {},
|
customizeWidgetColors = {},
|
||||||
topBarsScrolledContainerColor = MaterialTheme.colorScheme.primary,
|
|
||||||
nonScrolledTextColor = Color.White,
|
|
||||||
preventPhoneFromSleeping = false,
|
preventPhoneFromSleeping = false,
|
||||||
onPreventPhoneFromSleeping = {},
|
onPreventPhoneFromSleeping = {},
|
||||||
vibrateOnButtonPressFlow = false,
|
vibrateOnButtonPressFlow = false,
|
||||||
|
@ -219,8 +130,9 @@ private fun SettingsScreenPreview() {
|
||||||
isUseEnglishChecked = false,
|
isUseEnglishChecked = false,
|
||||||
onUseEnglishPress = {},
|
onUseEnglishPress = {},
|
||||||
onSetupLanguagePress = {},
|
onSetupLanguagePress = {},
|
||||||
useCommaAsDecimalMarkFlow = false, onUseCommaAsDecimalMarkFlow = {}, lockedCustomizeColorText = null,
|
useCommaAsDecimalMarkFlow = false,
|
||||||
topBarsContentColor = MaterialTheme.colorScheme.onPrimary
|
onUseCommaAsDecimalMarkFlow = {},
|
||||||
|
lockedCustomizeColorText = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ androidx-customViewPooling = "1.0.0"
|
||||||
androidx-lifecycle = "2.7.0-alpha01"
|
androidx-lifecycle = "2.7.0-alpha01"
|
||||||
#Compose
|
#Compose
|
||||||
composeActivity = "1.8.0-alpha06"
|
composeActivity = "1.8.0-alpha06"
|
||||||
compose = "1.6.0-alpha02"
|
compose = "1.6.0-alpha03"
|
||||||
composeCompiler = "1.5.1"
|
composeCompiler = "1.5.1"
|
||||||
composeMaterial3 = "1.2.0-alpha04"
|
composeMaterial3 = "1.2.0-alpha05"
|
||||||
accompanist = "0.31.6-rc"
|
accompanist = "0.33.0-alpha"
|
||||||
#AutoFitTextView
|
#AutoFitTextView
|
||||||
autofittextview = "0.2.1"
|
autofittextview = "0.2.1"
|
||||||
#exp4j
|
#exp4j
|
||||||
|
@ -22,7 +22,7 @@ room = "2.5.2"
|
||||||
#Simple tools
|
#Simple tools
|
||||||
simple-commons = "b80b717ad3"
|
simple-commons = "b80b717ad3"
|
||||||
#Gradle
|
#Gradle
|
||||||
gradlePlugins-agp = "8.1.0"
|
gradlePlugins-agp = "8.1.1"
|
||||||
#build
|
#build
|
||||||
app-build-compileSDKVersion = "34"
|
app-build-compileSDKVersion = "34"
|
||||||
app-build-targetSDK = "34"
|
app-build-targetSDK = "34"
|
||||||
|
|
Loading…
Reference in a new issue