upgrade to latest commons implementations and remove unnecessary code

This commit is contained in:
FunkyMuse 2023-08-23 10:44:44 +02:00
parent 6f5673d913
commit 796921fa51
7 changed files with 16 additions and 289 deletions

View File

@ -48,7 +48,9 @@ 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 displayLanguage = remember { Locale.getDefault().displayLanguage }
SettingsScreen( SettingsScreen(
displayLanguage = displayLanguage,
goBack = ::finish, goBack = ::finish,
customizeColors = ::handleCustomizeColorsClick, customizeColors = ::handleCustomizeColorsClick,
customizeWidgetColors = ::setupCustomizeWidgetColors, customizeWidgetColors = ::setupCustomizeWidgetColors,

View File

@ -1,23 +1,24 @@
package com.simplemobiletools.calculator.compose.screens package com.simplemobiletools.calculator.compose.screens
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.Spacer
import androidx.compose.material3.* 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.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
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.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.R
import com.simplemobiletools.commons.compose.extensions.MyDevices 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.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.helpers.isTiramisuPlus import com.simplemobiletools.commons.helpers.isTiramisuPlus
import java.util.Locale
@Composable @Composable
internal fun SettingsScreen( internal fun SettingsScreen(
@ -36,10 +37,10 @@ internal fun SettingsScreen(
onSetupLanguagePress: () -> Unit, onSetupLanguagePress: () -> Unit,
useCommaAsDecimalMarkFlow: Boolean, useCommaAsDecimalMarkFlow: Boolean,
onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit, onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit,
lockedCustomizeColorText: String? lockedCustomizeColorText: String?,
displayLanguage: String
) { ) {
val displayLanguage = remember { Locale.getDefault().displayLanguage } val startingPadding = remember { Modifier.padding(horizontal = 4.dp) }
val startingPadding = Modifier.padding(horizontal = 4.dp)
SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) { paddingValues -> SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) { paddingValues ->
SettingsGroup(title = { SettingsGroup(title = {
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization), modifier = startingPadding) SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization), modifier = startingPadding)
@ -132,7 +133,8 @@ private fun SettingsScreenPreview() {
onSetupLanguagePress = {}, onSetupLanguagePress = {},
useCommaAsDecimalMarkFlow = false, useCommaAsDecimalMarkFlow = false,
onUseCommaAsDecimalMarkFlow = {}, onUseCommaAsDecimalMarkFlow = {},
lockedCustomizeColorText = null lockedCustomizeColorText = null,
displayLanguage = "English"
) )
} }
} }

View File

@ -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",
)
}
}

View File

@ -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")
}
}
}
}

View File

@ -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,
)
}
}

View File

@ -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")
}

View File

@ -20,7 +20,7 @@ exp4j = "0.4.8"
#Room #Room
room = "2.5.2" room = "2.5.2"
#Simple tools #Simple tools
simple-commons = "b80b717ad3" simple-commons = "c3d56ea0d0"
#Gradle #Gradle
gradlePlugins-agp = "8.1.1" gradlePlugins-agp = "8.1.1"
#build #build