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,79 +36,11 @@ 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(
|
|
||||||
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 = {
|
SettingsGroup(title = {
|
||||||
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization), modifier = startingPadding)
|
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization), modifier = startingPadding)
|
||||||
}) {
|
}) {
|
||||||
|
@ -194,8 +108,7 @@ fun SettingsScreen(
|
||||||
modifier = startingPadding,
|
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