implement the status bar color and container color contrast, update kotlin and ksp
This commit is contained in:
parent
23867b022d
commit
5da68f1606
4 changed files with 36 additions and 18 deletions
|
@ -6,10 +6,12 @@ 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.extensions.TransparentSystemBars
|
||||
import com.simplemobiletools.calculator.compose.extensions.onEventValue
|
||||
import com.simplemobiletools.calculator.compose.screens.SettingsScreen
|
||||
import com.simplemobiletools.calculator.compose.theme.AppThemeSurface
|
||||
import com.simplemobiletools.calculator.compose.theme.OnLifecycleEvent
|
||||
|
@ -44,14 +46,13 @@ class SettingsActivity : AppCompatActivity() {
|
|||
(wasUseEnglishToggledFlow || Locale.getDefault().language != "en") && !isTiramisuPlus()
|
||||
}
|
||||
}
|
||||
var isOrWasThankYouInstalled by remember { mutableStateOf(false) }
|
||||
val isOrWasThankYouInstalled = onEventValue { context.isOrWasThankYouInstalled() }
|
||||
val statusBarColor = onEventValue { context.getColoredMaterialStatusBarColor() }
|
||||
val contrastColor = onEventValue { statusBarColor.getContrastColor() }
|
||||
|
||||
OnLifecycleEvent { event ->
|
||||
if (event == androidx.lifecycle.Lifecycle.Event.ON_START) {
|
||||
isOrWasThankYouInstalled = context.isOrWasThankYouInstalled()
|
||||
}
|
||||
}
|
||||
SettingsScreen(
|
||||
topBarsContentColor = Color(contrastColor),
|
||||
topBarsScrolledContainerColor = Color(statusBarColor),
|
||||
preventPhoneFromSleeping = preventPhoneFromSleeping,
|
||||
customizeColors = ::handleCustomizeColorsClick,
|
||||
goBack = ::finish,
|
||||
|
|
|
@ -4,10 +4,11 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
import com.simplemobiletools.calculator.compose.theme.OnLifecycleEvent
|
||||
|
||||
fun Context.getActivity(): Activity {
|
||||
if (this is Activity) return this
|
||||
|
@ -23,3 +24,15 @@ fun TransparentSystemBars() {
|
|||
systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = isSystemInDarkTheme)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T : Any> onEventValue(event: Lifecycle.Event = Lifecycle.Event.ON_START, value: () -> T): T {
|
||||
val rememberLatestUpdateState by rememberUpdatedState(newValue = value)
|
||||
var rememberedValue by remember { mutableStateOf(value()) }
|
||||
OnLifecycleEvent { lifecycleEvent ->
|
||||
if (lifecycleEvent == event) {
|
||||
rememberedValue = rememberLatestUpdateState()
|
||||
}
|
||||
}
|
||||
return rememberedValue
|
||||
}
|
||||
|
|
|
@ -48,7 +48,8 @@ fun SettingsScreen(
|
|||
onSetupLanguagePress: () -> Unit,
|
||||
useCommaAsDecimalMarkFlow: Boolean,
|
||||
onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit,
|
||||
lockedCustomizeColorText: String?
|
||||
lockedCustomizeColorText: String?,
|
||||
topBarsContentColor: Color
|
||||
) {
|
||||
val systemUiController = rememberSystemUiController()
|
||||
val displayLanguage = remember { Locale.getDefault().displayLanguage }
|
||||
|
@ -91,7 +92,9 @@ fun SettingsScreen(
|
|||
},
|
||||
scrollBehavior = scrollBehavior,
|
||||
colors = TopAppBarDefaults.largeTopAppBarColors(
|
||||
scrolledContainerColor = topBarsScrolledContainerColor
|
||||
scrolledContainerColor = topBarsScrolledContainerColor,
|
||||
containerColor = if (colorTransitionFraction == 1f) topBarsContentColor else MaterialTheme.colorScheme.surface,
|
||||
navigationIconContentColor = if (colorTransitionFraction == 1f) topBarsContentColor else MaterialTheme.colorScheme.surface
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@ -187,20 +190,21 @@ private fun SettingsScreenPreview() {
|
|||
goBack = {},
|
||||
customizeColors = {},
|
||||
customizeWidgetColors = {},
|
||||
topBarsScrolledContainerColor = MaterialTheme.colorScheme.primary,
|
||||
nonScrolledTextColor = Color.White,
|
||||
scrolledTextColor = Color.Black,
|
||||
preventPhoneFromSleeping = false,
|
||||
onPreventPhoneFromSleeping = {},
|
||||
vibrateOnButtonPressFlow = false,
|
||||
onVibrateOnButtonPressFlow = {},
|
||||
isOrWasThankYouInstalled = false,
|
||||
onThankYou = {},
|
||||
topBarsScrolledContainerColor = MaterialTheme.colorScheme.primary,
|
||||
nonScrolledTextColor = Color.White,
|
||||
scrolledTextColor = Color.Black,
|
||||
isUseEnglishEnabled = false,
|
||||
isUseEnglishChecked = false,
|
||||
onUseEnglishPress = {},
|
||||
onSetupLanguagePress = {}, useCommaAsDecimalMarkFlow = false, onUseCommaAsDecimalMarkFlow = {},
|
||||
lockedCustomizeColorText = null
|
||||
lockedCustomizeColorText = null,
|
||||
topBarsContentColor = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
[versions]
|
||||
#jetbrains
|
||||
kotlin = "1.8.22"
|
||||
kotlin = "1.9.0"
|
||||
#KSP
|
||||
ksp = "1.8.22-1.0.11"
|
||||
ksp = "1.9.0-1.0.12"
|
||||
#Androidx
|
||||
androidx-customView = "1.2.0-alpha02"
|
||||
androidx-customViewPooling = "1.0.0"
|
||||
|
@ -10,9 +10,9 @@ androidx-lifecycle = "2.6.1"
|
|||
#Compose
|
||||
composeActivity = "1.8.0-alpha06"
|
||||
compose = "1.6.0-alpha01"
|
||||
composeCompiler = "1.4.8"
|
||||
composeCompiler = "1.5.0"
|
||||
composeMaterial3 = "1.2.0-alpha03"
|
||||
accompanist = "0.31.4-beta"
|
||||
accompanist = "0.31.5-beta"
|
||||
#AutoFitTextView
|
||||
autofittextview = "0.2.1"
|
||||
#exp4j
|
||||
|
|
Loading…
Reference in a new issue