Fix wallpaper dim preference not applied correctly when launcher theme is set to dark but system is in light mode

This commit is contained in:
MM20 2022-10-22 13:12:07 +02:00
parent c577a4911d
commit 10d400a0c8
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 12 additions and 9 deletions

View File

@ -1,26 +1,29 @@
package de.mm20.launcher2.ui.launcher package de.mm20.launcher2.ui.launcher
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import de.mm20.launcher2.preferences.LauncherDataStore 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.MutableStateFlow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent import org.koin.core.component.KoinComponent
import org.koin.core.component.inject import org.koin.core.component.inject
class LauncherActivityVM : ViewModel(), KoinComponent { class LauncherActivityVM : ViewModel(), KoinComponent {
private val dataStore: LauncherDataStore by inject() private val dataStore: LauncherDataStore by inject()
private var isDarkInMode = MutableStateFlow(false) private var isSystemInDarkMode = MutableStateFlow(false)
private val dimBackgroundState = combine( private val dimBackgroundState = combine(
dataStore.data.map { it.appearance.dimWallpaper }, dataStore.data.map { it.appearance.dimWallpaper },
isDarkInMode dataStore.data.map { it.appearance.theme },
) { dim, darkMode -> isSystemInDarkMode
dim && darkMode ) { dim, theme, systemDarkMode ->
dim && (theme == Theme.Dark || theme == Theme.System && systemDarkMode)
} }
val dimBackground = dimBackgroundState.asLiveData() val dimBackground = dimBackgroundState.asLiveData()
@ -30,8 +33,8 @@ class LauncherActivityVM : ViewModel(), KoinComponent {
val hideNavBar = dataStore.data.map { it.systemBars.hideNavBar }.asLiveData() val hideNavBar = dataStore.data.map { it.systemBars.hideNavBar }.asLiveData()
val hideStatusBar = dataStore.data.map { it.systemBars.hideStatusBar }.asLiveData() val hideStatusBar = dataStore.data.map { it.systemBars.hideStatusBar }.asLiveData()
fun setDarkMode(darkMode: Boolean) { fun setSystemInDarkMode(darkMode: Boolean) {
isDarkInMode.value = darkMode isSystemInDarkMode.value = darkMode
} }
val layout = dataStore.data.map { it.appearance.layout }.asLiveData() val layout = dataStore.data.map { it.appearance.layout }.asLiveData()

View File

@ -73,7 +73,7 @@ abstract class SharedLauncherActivity(
WindowCompat.setDecorFitsSystemWindows(window, false) 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 { setContent {
val snackbarHostState = remember { SnackbarHostState() } val snackbarHostState = remember { SnackbarHostState() }