diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/ThemeManager.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/ThemeManager.kt index f1b0c2c11f..a53e3c6292 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/ThemeManager.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/ThemeManager.kt @@ -147,8 +147,7 @@ object ThemeManager { } fun applyThemeColor(name: ThemeColor, color: Color? = null, pref: MutableState) { - val prevValue = pref.value - pref.value = prevValue.withUpdatedColor(name, color?.toReadableHex()) + pref.value = pref.value.withUpdatedColor(name, color?.toReadableHex()) } fun saveAndApplyBackgroundImage(baseTheme: DefaultTheme, type: BackgroundImageType?, pref: SharedPreference> = appPrefs.themeOverrides) { 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 6942dfd718..09f1b70ed8 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 @@ -344,7 +344,11 @@ fun ChatInfoLayout( WallpaperButton { ModalManager.end.showModal { - WallpaperEditorModal(chat) + val chat = remember { derivedStateOf { chatModel.chats.firstOrNull { it.id == chat.id } } } + val c = chat.value + if (c != null) { + WallpaperEditorModal(c) + } } } // } else if (developerTools) { @@ -706,13 +710,13 @@ fun ModalData.WallpaperEditorModal(chat: Chat) { save = { applyToMode, newTheme -> withBGApi { var changedThemes: ThemeModeOverrides? = ((chat.chatInfo as? ChatInfo.Direct)?.contact?.uiThemes ?: (chat.chatInfo as? ChatInfo.Group)?.groupInfo?.uiThemes) ?: ThemeModeOverrides() - val changed = newTheme?.copy(mode = initialTheme.mode, wallpaper = newTheme.wallpaper?.withFilledWallpaperPath()) + val changed = newTheme?.copy(wallpaper = newTheme.wallpaper?.withFilledWallpaperPath()) changedThemes = if (applyToMode == null) { changedThemes?.copy(light = changed?.copy(mode = DefaultThemeMode.LIGHT), dark = changed?.copy(mode = DefaultThemeMode.DARK)) - } else if (changed?.mode == DefaultThemeMode.LIGHT) { - changedThemes?.copy(light = changed) + } else if (applyToMode == DefaultThemeMode.LIGHT) { + changedThemes?.copy(light = changed?.copy(mode = applyToMode)) } else { - changedThemes?.copy(dark = changed) + changedThemes?.copy(dark = changed?.copy(mode = applyToMode)) } changedThemes = if (changedThemes?.light != null || changedThemes?.dark != null) changedThemes else null if (controller.apiSetChatUIThemes(chat.remoteHostId, chat.id, changedThemes)) { @@ -829,6 +833,10 @@ fun ModalData.WallpaperEditor(theme: ThemeModeOverride, save: (applyToMode: Defa } } + KeyChangeEffect(theme.mode) { + themeModeOverride.value = theme + } + SectionSpacer() if (!showMore) { @@ -856,9 +864,6 @@ fun ModalData.WallpaperEditor(theme: ThemeModeOverride, save: (applyToMode: Defa } } ) - KeyChangeEffect(theme.mode) { - themeModeOverride.value = theme - } SectionSpacer() diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt index 3c65aa581c..0588c69e7c 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt @@ -237,7 +237,11 @@ fun GroupChatInfoLayout( WallpaperButton { ModalManager.end.showModal { - WallpaperEditorModal(chat) + val chat = remember { derivedStateOf { chatModel.chats.firstOrNull { it.id == chat.id } } } + val c = chat.value + if (c != null) { + WallpaperEditorModal(c) + } } } }