From 4fba96a75a13655c093d0f06ffa10c0f2789772e Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Tue, 17 Jan 2023 16:39:20 +0100 Subject: [PATCH] Merge LauncherActivityVM and LauncherScaffoldVM --- .../ui/launcher/LauncherActivityVM.kt | 43 ------------------- .../ui/launcher/LauncherScaffoldVM.kt | 32 +++++++++++++- 2 files changed, 31 insertions(+), 44 deletions(-) delete mode 100644 app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherActivityVM.kt diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherActivityVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherActivityVM.kt deleted file mode 100644 index 9647fa7a..00000000 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherActivityVM.kt +++ /dev/null @@ -1,43 +0,0 @@ -package de.mm20.launcher2.ui.launcher - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.asLiveData -import androidx.lifecycle.viewModelScope -import de.mm20.launcher2.preferences.LauncherDataStore -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 isSystemInDarkMode = MutableStateFlow(false) - - private val dimBackgroundState = combine( - dataStore.data.map { it.appearance.dimWallpaper }, - dataStore.data.map { it.appearance.theme }, - isSystemInDarkMode - ) { dim, theme, systemDarkMode -> - dim && (theme == Theme.Dark || theme == Theme.System && systemDarkMode) - } - val dimBackground = dimBackgroundState.asLiveData() - - val statusBarColor = dataStore.data.map { it.systemBars.statusBarColor }.asLiveData() - val navBarColor = dataStore.data.map { it.systemBars.statusBarColor }.asLiveData() - - val hideNavBar = dataStore.data.map { it.systemBars.hideNavBar }.asLiveData() - val hideStatusBar = dataStore.data.map { it.systemBars.hideStatusBar }.asLiveData() - - fun setSystemInDarkMode(darkMode: Boolean) { - isSystemInDarkMode.value = darkMode - } - - val baseLayout = dataStore.data.map { it.layout.baseLayout }.asLiveData() - val bottomSearchBar = dataStore.data.map { it.layout.bottomSearchBar }.asLiveData() - val reverseSearchResults = dataStore.data.map { it.layout.reverseSearchResults }.asLiveData() -} \ No newline at end of file diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherScaffoldVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherScaffoldVM.kt index 84aa8404..330142e4 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherScaffoldVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/LauncherScaffoldVM.kt @@ -5,6 +5,9 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.asLiveData import androidx.lifecycle.viewModelScope import de.mm20.launcher2.preferences.LauncherDataStore +import de.mm20.launcher2.preferences.Settings +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch @@ -12,12 +15,39 @@ import org.koin.core.component.KoinComponent import org.koin.core.component.inject class LauncherScaffoldVM : ViewModel(), KoinComponent { + + private val dataStore: LauncherDataStore by inject() + + private var isSystemInDarkMode = MutableStateFlow(false) + + private val dimBackgroundState = combine( + dataStore.data.map { it.appearance.dimWallpaper }, + dataStore.data.map { it.appearance.theme }, + isSystemInDarkMode + ) { dim, theme, systemDarkMode -> + dim && (theme == Settings.AppearanceSettings.Theme.Dark || theme == Settings.AppearanceSettings.Theme.System && systemDarkMode) + } + val dimBackground = dimBackgroundState.asLiveData() + + val statusBarColor = dataStore.data.map { it.systemBars.statusBarColor }.asLiveData() + val navBarColor = dataStore.data.map { it.systemBars.statusBarColor }.asLiveData() + + val hideNavBar = dataStore.data.map { it.systemBars.hideNavBar }.asLiveData() + val hideStatusBar = dataStore.data.map { it.systemBars.hideStatusBar }.asLiveData() + + fun setSystemInDarkMode(darkMode: Boolean) { + isSystemInDarkMode.value = darkMode + } + + val baseLayout = dataStore.data.map { it.layout.baseLayout }.asLiveData() + val bottomSearchBar = dataStore.data.map { it.layout.bottomSearchBar }.asLiveData() + val reverseSearchResults = dataStore.data.map { it.layout.reverseSearchResults }.asLiveData() + val isSearchOpen = MutableLiveData(false) val isWidgetEditMode = MutableLiveData(false) val searchBarFocused = MutableLiveData(false) - val dataStore: LauncherDataStore by inject() val autoFocusSearch = dataStore.data.map { it.searchBar.autoFocus }