Merge pull request #318 from FunkyMuse/master
fix: migrate to simple common's unified way of creating screens
This commit is contained in:
commit
d631f778d9
|
@ -6,11 +6,10 @@ 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
|
||||
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
|
||||
|
@ -49,16 +48,12 @@ 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() }
|
||||
}
|
||||
|
||||
val displayLanguage = remember { Locale.getDefault().displayLanguage }
|
||||
SettingsScreen(
|
||||
displayLanguage = displayLanguage,
|
||||
goBack = ::finish,
|
||||
customizeColors = ::handleCustomizeColorsClick,
|
||||
customizeWidgetColors = ::setupCustomizeWidgetColors,
|
||||
topBarsScrolledContainerColor = Color(statusBarColor),
|
||||
preventPhoneFromSleeping = preventPhoneFromSleeping,
|
||||
onPreventPhoneFromSleeping = preferences::preventPhoneFromSleeping::set,
|
||||
vibrateOnButtonPressFlow = vibrateOnButtonPressFlow,
|
||||
|
@ -80,8 +75,7 @@ class SettingsActivity : AppCompatActivity() {
|
|||
applicationContext.calculatorDB.deleteHistory()
|
||||
}
|
||||
},
|
||||
lockedCustomizeColorText = lockedCustomizeColorText,
|
||||
topBarsContentColor = Color(contrastColor)
|
||||
lockedCustomizeColorText = lockedCustomizeColorText
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
package com.simplemobiletools.calculator.compose
|
||||
|
||||
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.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
|
||||
|
||||
@Composable
|
||||
internal fun SettingsScreen(
|
||||
goBack: () -> Unit,
|
||||
customizeColors: () -> Unit,
|
||||
customizeWidgetColors: () -> Unit,
|
||||
preventPhoneFromSleeping: Boolean,
|
||||
onPreventPhoneFromSleeping: (Boolean) -> Unit,
|
||||
vibrateOnButtonPressFlow: Boolean,
|
||||
onVibrateOnButtonPressFlow: (Boolean) -> Unit,
|
||||
isOrWasThankYouInstalled: Boolean,
|
||||
onThankYou: () -> Unit,
|
||||
isUseEnglishEnabled: Boolean,
|
||||
isUseEnglishChecked: Boolean,
|
||||
onUseEnglishPress: (Boolean) -> Unit,
|
||||
onSetupLanguagePress: () -> Unit,
|
||||
useCommaAsDecimalMarkFlow: Boolean,
|
||||
onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit,
|
||||
lockedCustomizeColorText: String?,
|
||||
displayLanguage: String
|
||||
) {
|
||||
SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) { paddingValues ->
|
||||
SettingsGroup(title = {
|
||||
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization))
|
||||
}) {
|
||||
SettingsPreferenceComponent(
|
||||
preferenceTitle = stringResource(id = R.string.customize_colors),
|
||||
doOnPreferenceClick = customizeColors,
|
||||
isPreferenceEnabled = isOrWasThankYouInstalled,
|
||||
preferenceSummary = lockedCustomizeColorText
|
||||
)
|
||||
SettingsPreferenceComponent(
|
||||
preferenceTitle = stringResource(id = R.string.customize_widget_colors),
|
||||
doOnPreferenceClick = customizeWidgetColors
|
||||
)
|
||||
}
|
||||
HorizontalDivider(color = divider_grey)
|
||||
SettingsGroup(title = {
|
||||
SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings))
|
||||
}) {
|
||||
if (!isOrWasThankYouInstalled) {
|
||||
SettingsPreferenceComponent(
|
||||
preferenceTitle = stringResource(id = R.string.purchase_simple_thank_you),
|
||||
doOnPreferenceClick = onThankYou,
|
||||
)
|
||||
}
|
||||
if (isUseEnglishEnabled) {
|
||||
SettingsCheckBoxComponent(
|
||||
title = stringResource(id = R.string.use_english_language),
|
||||
initialValue = isUseEnglishChecked,
|
||||
onChange = onUseEnglishPress,
|
||||
)
|
||||
}
|
||||
if (isTiramisuPlus()) {
|
||||
SettingsPreferenceComponent(
|
||||
preferenceTitle = stringResource(id = R.string.language),
|
||||
preferenceSummary = displayLanguage,
|
||||
doOnPreferenceClick = onSetupLanguagePress,
|
||||
preferenceSummaryColor = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
}
|
||||
SettingsCheckBoxComponent(
|
||||
title = stringResource(id = R.string.vibrate_on_button_press),
|
||||
initialValue = vibrateOnButtonPressFlow,
|
||||
onChange = onVibrateOnButtonPressFlow,
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
title = stringResource(id = R.string.prevent_phone_from_sleeping),
|
||||
initialValue = preventPhoneFromSleeping,
|
||||
onChange = onPreventPhoneFromSleeping,
|
||||
)
|
||||
SettingsCheckBoxComponent(
|
||||
title = stringResource(id = com.simplemobiletools.calculator.R.string.use_comma_as_decimal_mark),
|
||||
initialValue = useCommaAsDecimalMarkFlow,
|
||||
onChange = onUseCommaAsDecimalMarkFlow,
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()))
|
||||
}
|
||||
}
|
||||
|
||||
@MyDevices
|
||||
@Composable
|
||||
private fun SettingsScreenPreview() {
|
||||
AppThemeSurface {
|
||||
SettingsScreen(
|
||||
goBack = {},
|
||||
customizeColors = {},
|
||||
customizeWidgetColors = {},
|
||||
preventPhoneFromSleeping = false,
|
||||
onPreventPhoneFromSleeping = {},
|
||||
vibrateOnButtonPressFlow = false,
|
||||
onVibrateOnButtonPressFlow = {},
|
||||
isOrWasThankYouInstalled = false,
|
||||
onThankYou = {},
|
||||
isUseEnglishEnabled = false,
|
||||
isUseEnglishChecked = false,
|
||||
onUseEnglishPress = {},
|
||||
onSetupLanguagePress = {},
|
||||
useCommaAsDecimalMarkFlow = false,
|
||||
onUseCommaAsDecimalMarkFlow = {},
|
||||
lockedCustomizeColorText = null,
|
||||
displayLanguage = "English"
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
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.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(
|
||||
goBack: () -> Unit,
|
||||
customizeColors: () -> Unit,
|
||||
customizeWidgetColors: () -> Unit,
|
||||
topBarsScrolledContainerColor: Color,
|
||||
nonScrolledTextColor: Color = if (isSurfaceLitWell()) Color.Black else Color.White,
|
||||
preventPhoneFromSleeping: Boolean,
|
||||
onPreventPhoneFromSleeping: (Boolean) -> Unit,
|
||||
vibrateOnButtonPressFlow: Boolean,
|
||||
onVibrateOnButtonPressFlow: (Boolean) -> Unit,
|
||||
isOrWasThankYouInstalled: Boolean,
|
||||
onThankYou: () -> Unit,
|
||||
isUseEnglishEnabled: Boolean,
|
||||
isUseEnglishChecked: Boolean,
|
||||
onUseEnglishPress: (Boolean) -> Unit,
|
||||
onSetupLanguagePress: () -> Unit,
|
||||
useCommaAsDecimalMarkFlow: Boolean,
|
||||
onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit,
|
||||
lockedCustomizeColorText: String?,
|
||||
topBarsContentColor: Color
|
||||
) {
|
||||
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
|
||||
),
|
||||
)
|
||||
}
|
||||
) { 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,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MyDevices
|
||||
@Composable
|
||||
private fun SettingsScreenPreview() {
|
||||
AppThemeSurface {
|
||||
SettingsScreen(
|
||||
goBack = {},
|
||||
customizeColors = {},
|
||||
customizeWidgetColors = {},
|
||||
topBarsScrolledContainerColor = MaterialTheme.colorScheme.primary,
|
||||
nonScrolledTextColor = Color.White,
|
||||
preventPhoneFromSleeping = false,
|
||||
onPreventPhoneFromSleeping = {},
|
||||
vibrateOnButtonPressFlow = false,
|
||||
onVibrateOnButtonPressFlow = {},
|
||||
isOrWasThankYouInstalled = false,
|
||||
onThankYou = {},
|
||||
isUseEnglishEnabled = false,
|
||||
isUseEnglishChecked = false,
|
||||
onUseEnglishPress = {},
|
||||
onSetupLanguagePress = {},
|
||||
useCommaAsDecimalMarkFlow = false, onUseCommaAsDecimalMarkFlow = {}, lockedCustomizeColorText = null,
|
||||
topBarsContentColor = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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",
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
}
|
|
@ -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.5-beta"
|
||||
composeMaterial3 = "1.2.0-alpha05"
|
||||
accompanist = "0.33.0-alpha"
|
||||
#AutoFitTextView
|
||||
autofittextview = "0.2.1"
|
||||
#exp4j
|
||||
|
@ -20,9 +20,9 @@ exp4j = "0.4.8"
|
|||
#Room
|
||||
room = "2.5.2"
|
||||
#Simple tools
|
||||
simple-commons = "b80b717ad3"
|
||||
simple-commons = "565200547d"
|
||||
#Gradle
|
||||
gradlePlugins-agp = "8.1.0"
|
||||
gradlePlugins-agp = "8.1.1"
|
||||
#build
|
||||
app-build-compileSDKVersion = "34"
|
||||
app-build-targetSDK = "34"
|
||||
|
|
Loading…
Reference in New Issue