Merge LauncherActivityVM and LauncherScaffoldVM

This commit is contained in:
MM20 2023-01-17 16:39:20 +01:00
parent 8e5eb68e60
commit 4fba96a75a
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 31 additions and 44 deletions

View File

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

View File

@ -5,6 +5,9 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import de.mm20.launcher2.preferences.LauncherDataStore 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.first
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -12,12 +15,39 @@ import org.koin.core.component.KoinComponent
import org.koin.core.component.inject import org.koin.core.component.inject
class LauncherScaffoldVM : ViewModel(), KoinComponent { 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 isSearchOpen = MutableLiveData(false)
val isWidgetEditMode = MutableLiveData(false) val isWidgetEditMode = MutableLiveData(false)
val searchBarFocused = MutableLiveData(false) val searchBarFocused = MutableLiveData(false)
val dataStore: LauncherDataStore by inject()
val autoFocusSearch = dataStore.data.map { it.searchBar.autoFocus } val autoFocusSearch = dataStore.data.map { it.searchBar.autoFocus }