implement the status bar color and container color contrast, update kotlin and ksp

This commit is contained in:
FunkyMuse 2023-07-21 11:47:00 +02:00
parent 23867b022d
commit 5da68f1606
4 changed files with 36 additions and 18 deletions

View file

@ -6,10 +6,12 @@ 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
import com.simplemobiletools.calculator.compose.extensions.TransparentSystemBars 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.screens.SettingsScreen
import com.simplemobiletools.calculator.compose.theme.AppThemeSurface import com.simplemobiletools.calculator.compose.theme.AppThemeSurface
import com.simplemobiletools.calculator.compose.theme.OnLifecycleEvent import com.simplemobiletools.calculator.compose.theme.OnLifecycleEvent
@ -44,14 +46,13 @@ class SettingsActivity : AppCompatActivity() {
(wasUseEnglishToggledFlow || Locale.getDefault().language != "en") && !isTiramisuPlus() (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( SettingsScreen(
topBarsContentColor = Color(contrastColor),
topBarsScrolledContainerColor = Color(statusBarColor),
preventPhoneFromSleeping = preventPhoneFromSleeping, preventPhoneFromSleeping = preventPhoneFromSleeping,
customizeColors = ::handleCustomizeColorsClick, customizeColors = ::handleCustomizeColorsClick,
goBack = ::finish, goBack = ::finish,

View file

@ -4,10 +4,11 @@ import android.app.Activity
import android.content.Context import android.content.Context
import android.content.ContextWrapper import android.content.ContextWrapper
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.*
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.lifecycle.Lifecycle
import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.simplemobiletools.calculator.compose.theme.OnLifecycleEvent
fun Context.getActivity(): Activity { fun Context.getActivity(): Activity {
if (this is Activity) return this if (this is Activity) return this
@ -23,3 +24,15 @@ fun TransparentSystemBars() {
systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = isSystemInDarkTheme) 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
}

View file

@ -48,7 +48,8 @@ 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 systemUiController = rememberSystemUiController()
val displayLanguage = remember { Locale.getDefault().displayLanguage } val displayLanguage = remember { Locale.getDefault().displayLanguage }
@ -91,7 +92,9 @@ fun SettingsScreen(
}, },
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
colors = TopAppBarDefaults.largeTopAppBarColors( 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 = {}, goBack = {},
customizeColors = {}, customizeColors = {},
customizeWidgetColors = {}, customizeWidgetColors = {},
topBarsScrolledContainerColor = MaterialTheme.colorScheme.primary,
nonScrolledTextColor = Color.White,
scrolledTextColor = Color.Black,
preventPhoneFromSleeping = false, preventPhoneFromSleeping = false,
onPreventPhoneFromSleeping = {}, onPreventPhoneFromSleeping = {},
vibrateOnButtonPressFlow = false, vibrateOnButtonPressFlow = false,
onVibrateOnButtonPressFlow = {}, onVibrateOnButtonPressFlow = {},
isOrWasThankYouInstalled = false, isOrWasThankYouInstalled = false,
onThankYou = {}, onThankYou = {},
topBarsScrolledContainerColor = MaterialTheme.colorScheme.primary,
nonScrolledTextColor = Color.White,
scrolledTextColor = Color.Black,
isUseEnglishEnabled = false, isUseEnglishEnabled = false,
isUseEnglishChecked = false, isUseEnglishChecked = false,
onUseEnglishPress = {}, onUseEnglishPress = {},
onSetupLanguagePress = {}, useCommaAsDecimalMarkFlow = false, onUseCommaAsDecimalMarkFlow = {}, onSetupLanguagePress = {}, useCommaAsDecimalMarkFlow = false, onUseCommaAsDecimalMarkFlow = {},
lockedCustomizeColorText = null lockedCustomizeColorText = null,
topBarsContentColor = MaterialTheme.colorScheme.onPrimary
) )
} }
} }

View file

@ -1,8 +1,8 @@
[versions] [versions]
#jetbrains #jetbrains
kotlin = "1.8.22" kotlin = "1.9.0"
#KSP #KSP
ksp = "1.8.22-1.0.11" ksp = "1.9.0-1.0.12"
#Androidx #Androidx
androidx-customView = "1.2.0-alpha02" androidx-customView = "1.2.0-alpha02"
androidx-customViewPooling = "1.0.0" androidx-customViewPooling = "1.0.0"
@ -10,9 +10,9 @@ androidx-lifecycle = "2.6.1"
#Compose #Compose
composeActivity = "1.8.0-alpha06" composeActivity = "1.8.0-alpha06"
compose = "1.6.0-alpha01" compose = "1.6.0-alpha01"
composeCompiler = "1.4.8" composeCompiler = "1.5.0"
composeMaterial3 = "1.2.0-alpha03" composeMaterial3 = "1.2.0-alpha03"
accompanist = "0.31.4-beta" accompanist = "0.31.5-beta"
#AutoFitTextView #AutoFitTextView
autofittextview = "0.2.1" autofittextview = "0.2.1"
#exp4j #exp4j