Added Dynamic Colors setting
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Build
|
||||
import android.os.Build.VERSION
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
@ -23,31 +23,40 @@ import androidx.core.view.WindowCompat
|
||||
fun AppTheme(
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val useDarkTheme by remember { BaresipService.darkTheme }
|
||||
val useDynamicColors by remember { BaresipService.dynamicColors }
|
||||
|
||||
val useActualDynamicColors = useDynamicColors && VERSION.SDK_INT >= 31
|
||||
Log.d(TAG, "Use actual dynamic colors: $useActualDynamicColors")
|
||||
|
||||
val colorScheme = when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
if (useDarkTheme)
|
||||
dynamicDarkColorScheme(context = LocalContext.current)
|
||||
useActualDynamicColors -> {
|
||||
if (useDarkTheme || isSystemInDarkTheme())
|
||||
dynamicDarkColorScheme(context)
|
||||
else
|
||||
if (isSystemInDarkTheme())
|
||||
dynamicDarkColorScheme(context = LocalContext.current)
|
||||
else
|
||||
dynamicLightColorScheme(context = LocalContext.current)
|
||||
dynamicLightColorScheme(context)
|
||||
}
|
||||
useDarkTheme -> darkColorScheme()
|
||||
else ->
|
||||
if (isSystemInDarkTheme())
|
||||
darkColorScheme()
|
||||
else
|
||||
lightColorScheme()
|
||||
useDarkTheme || isSystemInDarkTheme() -> darkColorScheme()
|
||||
else -> lightColorScheme()
|
||||
}
|
||||
|
||||
val customColorsPalette =
|
||||
(if (useDarkTheme) DarkCustomColors else LightCustomColors).copy(
|
||||
val basePalette = if (useDarkTheme) DarkCustomColors else LightCustomColors
|
||||
|
||||
val customColorsPalette = basePalette.copy(
|
||||
background = colorScheme.background,
|
||||
cardBackground = colorScheme.surfaceVariant,
|
||||
textFieldBackground = colorScheme.surfaceVariant
|
||||
textFieldBackground = colorScheme.surfaceVariant,
|
||||
primary = if (useActualDynamicColors) {
|
||||
colorScheme.primary
|
||||
} else {
|
||||
basePalette.primary
|
||||
},
|
||||
onPrimary = if (useActualDynamicColors) {
|
||||
colorScheme.onPrimary
|
||||
} else {
|
||||
basePalette.onPrimary
|
||||
}
|
||||
)
|
||||
|
||||
val view = LocalView.current
|
||||
|
||||
@ -1750,6 +1750,7 @@ class BaresipService: Service() {
|
||||
val androidContacts = mutableStateOf(emptyList<Contact.AndroidContact>())
|
||||
val contactNames = mutableStateOf(emptyList<String>())
|
||||
val darkTheme = mutableStateOf(false)
|
||||
val dynamicColors = mutableStateOf(false)
|
||||
var messages by mutableStateOf(emptyList<Message>())
|
||||
val messageUpdate = MutableLiveData<Long>()
|
||||
val registrationUpdate = MutableLiveData<Long>()
|
||||
|
||||
@ -119,6 +119,15 @@ object Config {
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
|
||||
val dynamicColors = previousVariable("dynamic_colors")
|
||||
BaresipService.dynamicColors.value = if (dynamicColors == "yes") {
|
||||
config = "${config}dynamic_colors yes\n"
|
||||
true
|
||||
} else {
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
false
|
||||
}
|
||||
|
||||
val colorblind = previousVariable("colorblind")
|
||||
config = if (colorblind != "")
|
||||
"${config}colorblind $colorblind\n"
|
||||
|
||||
@ -90,6 +90,8 @@ private var save = false
|
||||
|
||||
private var oldBatteryOptimizations = false
|
||||
private var oldDarkTheme = false
|
||||
|
||||
private var oldDynamicColors = false
|
||||
private var oldDefaultDialer = false
|
||||
|
||||
fun NavGraphBuilder.settingsScreenRoute(
|
||||
@ -104,6 +106,8 @@ fun NavGraphBuilder.settingsScreenRoute(
|
||||
|
||||
oldDarkTheme = Preferences(ctx).displayTheme == AppCompatDelegate.MODE_NIGHT_YES
|
||||
|
||||
oldDynamicColors = BaresipService.dynamicColors.value
|
||||
|
||||
if (VERSION.SDK_INT >= 29) {
|
||||
val roleManager = ctx.getSystemService(ROLE_SERVICE) as RoleManager
|
||||
oldDefaultDialer = roleManager.isRoleHeld(RoleManager.ROLE_DIALER)
|
||||
@ -246,6 +250,8 @@ private var newBatteryOptimizations = false
|
||||
|
||||
private var newDarkTheme = false
|
||||
|
||||
private var newDynamicColors = false
|
||||
|
||||
private var newColorblind = false
|
||||
|
||||
private var newProximitySensing = true
|
||||
@ -316,6 +322,8 @@ private fun SettingsContent(
|
||||
Ringtone(ctx)
|
||||
BatteryOptimizations()
|
||||
DarkTheme()
|
||||
if (VERSION.SDK_INT >= 31)
|
||||
DynamicColors()
|
||||
ColorBlind()
|
||||
ProximitySensing()
|
||||
if (VERSION.SDK_INT >= 29)
|
||||
@ -1099,6 +1107,38 @@ private fun DarkTheme() {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DynamicColors() {
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Start
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
Text(text = stringResource(R.string.dynamic_colors),
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.clickable {
|
||||
alertTitle.value = ctx.getString(R.string.dynamic_colors)
|
||||
alertMessage.value = ctx.getString(R.string.dynamic_colors_help)
|
||||
showAlert.value = true
|
||||
},
|
||||
color = LocalCustomColors.current.itemText,
|
||||
fontSize = 18.sp)
|
||||
var dynamicColors by remember { mutableStateOf(oldDynamicColors) }
|
||||
newDynamicColors = dynamicColors
|
||||
Switch(
|
||||
checked = dynamicColors,
|
||||
onCheckedChange = {
|
||||
dynamicColors = it
|
||||
newDynamicColors = dynamicColors
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ColorBlind() {
|
||||
Row(
|
||||
@ -1447,6 +1487,13 @@ private fun checkOnClick(ctx: Context) {
|
||||
save = true
|
||||
}
|
||||
|
||||
if (oldDynamicColors != newDynamicColors) {
|
||||
BaresipService.dynamicColors.value = newDynamicColors
|
||||
Config.replaceVariable("dynamic_colors",
|
||||
if (newDynamicColors) "yes" else "no")
|
||||
save = true
|
||||
}
|
||||
|
||||
if ((Config.variable("colorblind") == "yes") != newColorblind) {
|
||||
Config.replaceVariable(
|
||||
"colorblind",
|
||||
|
||||
@ -396,6 +396,8 @@
|
||||
<string name="tone_country_help">Country of call ringing, waiting, and callee busy tones</string>
|
||||
<string name="dark_theme">Dark Theme</string>
|
||||
<string name="dark_theme_help">Force dark display theme</string>
|
||||
<string name="dynamic_colors">Dynamic Colors</string>
|
||||
<string name="dynamic_colors_help">Use dynamic colors if enabled in Android Settings</string>
|
||||
<string name="colorblind">Colorblind</string>
|
||||
<string name="colorblind_help">Use colorblind friendly registration status icons</string>
|
||||
<string name="proximity_sensing">Proximity Sensing</string>">
|
||||
|
||||
Reference in New Issue
Block a user