fix state update

This commit is contained in:
Avently
2024-05-09 22:02:19 +07:00
parent 4475f0707c
commit 8fddc6fdaa
3 changed files with 19 additions and 11 deletions

View File

@@ -147,8 +147,7 @@ object ThemeManager {
}
fun applyThemeColor(name: ThemeColor, color: Color? = null, pref: MutableState<ThemeModeOverride>) {
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<Map<String, ThemeOverrides>> = appPrefs.themeOverrides) {

View File

@@ -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()

View File

@@ -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)
}
}
}
}