refactor: global state and hydration
Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
parent
795f288ab8
commit
d33315b49f
|
|
@ -1,15 +1,15 @@
|
|||
package chat.revolt.api.settings
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import chat.revolt.ui.theme.Theme
|
||||
import chat.revolt.ui.theme.getDefaultTheme
|
||||
|
||||
object GlobalState {
|
||||
private var _theme = mutableStateOf(getDefaultTheme())
|
||||
val theme
|
||||
get() = _theme.value
|
||||
var theme by mutableStateOf(getDefaultTheme())
|
||||
|
||||
fun setTheme(theme: Theme) {
|
||||
_theme.value = theme
|
||||
fun hydrateWithSettings(settings: SyncedSettings) {
|
||||
settings.android.theme?.let { this.theme = Theme.valueOf(it) }
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,6 @@ import chat.revolt.api.settings.SyncedSettings
|
|||
import chat.revolt.components.screens.splash.DisconnectedScreen
|
||||
import chat.revolt.persistence.KVStorage
|
||||
import chat.revolt.ui.theme.RevoltColorScheme
|
||||
import chat.revolt.ui.theme.Theme
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.ktor.client.request.get
|
||||
|
|
@ -129,7 +128,7 @@ class SplashScreenViewModel @Inject constructor(
|
|||
private fun loadSettings() {
|
||||
viewModelScope.launch {
|
||||
SyncedSettings.fetch()
|
||||
SyncedSettings.android.theme?.let { GlobalState.setTheme(Theme.valueOf(it)) }
|
||||
GlobalState.hydrateWithSettings(SyncedSettings)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ fun AppearanceSettingsScreen(
|
|||
val context = LocalContext.current
|
||||
|
||||
fun setNewTheme(theme: Theme) {
|
||||
GlobalState.setTheme(theme)
|
||||
GlobalState.theme = theme
|
||||
viewModel.saveNewTheme(theme)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue