From 2b8987f55dc6e8e8c6f17d3c2b3bc707161f5cce Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Thu, 9 May 2024 22:16:37 +0700 Subject: [PATCH] different defaults --- .../kotlin/chat/simplex/common/ui/theme/Theme.kt | 8 +++----- .../chat/simplex/common/views/chat/ChatInfoView.kt | 14 +++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/Theme.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/Theme.kt index 1de321c664..f07a58bcda 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/Theme.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/Theme.kt @@ -342,11 +342,9 @@ data class ThemeModeOverrides ( val light: ThemeModeOverride? = null, val dark: ThemeModeOverride? = null ) { - fun preferredTheme(baseTheme: DefaultTheme = CurrentColors.value.base): ThemeModeOverride? { - return when (baseTheme) { - DefaultTheme.LIGHT -> light - else -> dark - } + fun preferredTheme(baseTheme: DefaultTheme = CurrentColors.value.base): ThemeModeOverride? = when (baseTheme) { + DefaultTheme.LIGHT -> light + else -> dark } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt index 09f1b70ed8..cf899c7287 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt @@ -700,13 +700,17 @@ fun ShareAddressButton(onClick: () -> Unit) { @Composable fun ModalData.WallpaperEditorModal(chat: Chat) { + val themes = remember(CurrentColors.value.base) { + (chat.chatInfo as? ChatInfo.Direct)?.contact?.uiThemes + ?: (chat.chatInfo as? ChatInfo.Group)?.groupInfo?.uiThemes + ?: ThemeModeOverrides() + } val initialTheme = remember(CurrentColors.value.base) { - (chat.chatInfo as? ChatInfo.Direct)?.contact?.uiThemes?.preferredTheme()?.copy(mode = CurrentColors.value.base.mode) - ?: (chat.chatInfo as? ChatInfo.Group)?.groupInfo?.uiThemes?.preferredTheme()?.copy(mode = CurrentColors.value.base.mode) - ?: ThemeModeOverride() + (themes.preferredTheme() ?: ThemeModeOverride()).copy(mode = CurrentColors.value.base.mode) } WallpaperEditor( initialTheme, + applyToMode = if (themes.light == themes.dark) null else initialTheme.mode, save = { applyToMode, newTheme -> withBGApi { var changedThemes: ThemeModeOverrides? = ((chat.chatInfo as? ChatInfo.Direct)?.contact?.uiThemes ?: (chat.chatInfo as? ChatInfo.Group)?.groupInfo?.uiThemes) ?: ThemeModeOverrides() @@ -753,12 +757,12 @@ fun ModalData.WallpaperEditorModal(chat: Chat) { } @Composable -fun ModalData.WallpaperEditor(theme: ThemeModeOverride, save: (applyToMode: DefaultThemeMode?, ThemeModeOverride?) -> Unit, setDefaultsToAll: suspend () -> ThemeModeOverride) { +fun ModalData.WallpaperEditor(theme: ThemeModeOverride, applyToMode: DefaultThemeMode?, save: (applyToMode: DefaultThemeMode?, ThemeModeOverride?) -> Unit, setDefaultsToAll: suspend () -> ThemeModeOverride) { ColumnWithScrollBar( Modifier .fillMaxSize() ) { - val applyToMode = remember { stateGetOrPutNullable("applyToMode") { null as DefaultThemeMode? } } + val applyToMode = remember { stateGetOrPutNullable("applyToMode") { applyToMode } } var showMore by remember { stateGetOrPut("showMore") { false } } val themeModeOverride = remember { stateGetOrPut("themeModeOverride") { theme } } val backgroundImageType: State = remember { derivedStateOf { BackgroundImageType.from(themeModeOverride.value.wallpaper) } }