color mode switcher

This commit is contained in:
Diogo
2024-08-29 16:13:16 +01:00
parent 0cd1208daa
commit ff8e55599b
2 changed files with 41 additions and 5 deletions
@@ -34,6 +34,7 @@ import chat.simplex.common.platform.*
import chat.simplex.common.views.CreateProfile
import chat.simplex.common.views.remote.*
import chat.simplex.common.views.usersettings.*
import chat.simplex.common.views.usersettings.AppearanceScope.ColorModeSwitcher
import chat.simplex.res.MR
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.coroutines.*
@@ -391,11 +392,15 @@ fun UserPicker(
}
if (showSettings) {
Divider(Modifier.padding(DEFAULT_PADDING))
UserPickerOptionRow(
painterResource(MR.images.ic_settings),
generalGetString(MR.strings.settings_section_title_settings).lowercase().capitalize(Locale.current),
settingsClicked
)
val text = generalGetString(MR.strings.settings_section_title_settings).lowercase().capitalize(Locale.current)
SectionItemView(settingsClicked) {
Icon(painterResource(MR.images.ic_settings), text, tint = MenuTextColor)
TextIconSpaced()
Text(text, color = MenuTextColor)
Spacer(Modifier.weight(1f))
ColorModeSwitcher()
}
}
if (showCancel) {
CancelPickerItem(cancelClicked)
@@ -9,6 +9,7 @@ import SectionView
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.material.MaterialTheme.colors
@@ -606,6 +607,36 @@ object AppearanceScope {
}
}
@Composable
fun ColorModeSwitcher() {
val currentTheme by CurrentColors.collectAsState()
var themeMode = currentTheme.base.mode;
if (appPrefs.currentTheme.get() === DefaultTheme.SYSTEM_THEME_NAME) {
themeMode = if (systemInDarkThemeCurrently) DefaultThemeMode.DARK else DefaultThemeMode.LIGHT
}
Column(
modifier = Modifier
.clip(CircleShape)
.combinedClickable(
onClick = {
ThemeManager.applyTheme(if (themeMode == DefaultThemeMode.LIGHT) appPrefs.systemDarkTheme.get()!! else DefaultTheme.LIGHT.themeName)
saveThemeToDatabase(null)
},
onLongClick = {
ThemeManager.applyTheme(DefaultTheme.SYSTEM_THEME_NAME)
saveThemeToDatabase(null)
}
)
.size(44.dp * fontSizeSqrtMultiplier),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(painterResource(MR.images.ic_light_mode), stringResource(MR.strings.color_mode_light), tint = MenuTextColor)
}
}
private var updateBackendJob: Job = Job()
private fun saveThemeToDatabase(themeUserDestination: Pair<Long, ThemeModeOverrides?>?) {
val remoteHostId = chatModel.remoteHostId()