From 10d400a0c81ad4f401532dfa57f69111310737ce Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sat, 22 Oct 2022 13:12:07 +0200 Subject: [PATCH] Fix wallpaper dim preference not applied correctly when launcher theme is set to dark but system is in light mode --- .../ui/launcher/LauncherActivityVM.kt | 19 +++++++++++-------- .../ui/launcher/SharedLauncherActivity.kt | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherActivityVM.kt b/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherActivityVM.kt index 181c8ca4..7023bbe9 100644 --- a/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherActivityVM.kt +++ b/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherActivityVM.kt @@ -1,26 +1,29 @@ package de.mm20.launcher2.ui.launcher -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.asLiveData +import androidx.lifecycle.viewModelScope import de.mm20.launcher2.preferences.LauncherDataStore -import de.mm20.launcher2.preferences.Settings.SystemBarsSettings +import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Theme import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map +import kotlinx.coroutines.launch import org.koin.core.component.KoinComponent import org.koin.core.component.inject class LauncherActivityVM : ViewModel(), KoinComponent { private val dataStore: LauncherDataStore by inject() - private var isDarkInMode = MutableStateFlow(false) + private var isSystemInDarkMode = MutableStateFlow(false) private val dimBackgroundState = combine( dataStore.data.map { it.appearance.dimWallpaper }, - isDarkInMode - ) { dim, darkMode -> - dim && darkMode + dataStore.data.map { it.appearance.theme }, + isSystemInDarkMode + ) { dim, theme, systemDarkMode -> + dim && (theme == Theme.Dark || theme == Theme.System && systemDarkMode) } val dimBackground = dimBackgroundState.asLiveData() @@ -30,8 +33,8 @@ class LauncherActivityVM : ViewModel(), KoinComponent { val hideNavBar = dataStore.data.map { it.systemBars.hideNavBar }.asLiveData() val hideStatusBar = dataStore.data.map { it.systemBars.hideStatusBar }.asLiveData() - fun setDarkMode(darkMode: Boolean) { - isDarkInMode.value = darkMode + fun setSystemInDarkMode(darkMode: Boolean) { + isSystemInDarkMode.value = darkMode } val layout = dataStore.data.map { it.appearance.layout }.asLiveData() diff --git a/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt b/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt index 3b84df96..46d85928 100644 --- a/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt +++ b/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt @@ -73,7 +73,7 @@ abstract class SharedLauncherActivity( WindowCompat.setDecorFitsSystemWindows(window, false) - viewModel.setDarkMode(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) + viewModel.setSystemInDarkMode(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) setContent { val snackbarHostState = remember { SnackbarHostState() }