Replace DataStore delegate magic with direct usage
This commit is contained in:
parent
5621e3b4ac
commit
80eb10f018
2 changed files with 7 additions and 14 deletions
|
@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.*
|
|||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.*
|
||||
import androidx.compose.ui.unit.*
|
||||
import androidx.datastore.preferences.*
|
||||
import androidx.datastore.preferences.core.*
|
||||
import androidx.lifecycle.*
|
||||
import kotlinx.coroutines.*
|
||||
|
@ -15,13 +16,15 @@ import kotlinx.coroutines.flow.*
|
|||
|
||||
|
||||
class MainActivity : EdgeToEdgeActivity () {
|
||||
val dataStore = PreferenceDataStoreFactory . create { preferencesDataStoreFile ("state") }
|
||||
|
||||
override fun onCreate ( savedInstanceState : Bundle ? ) {
|
||||
super . onCreate (savedInstanceState)
|
||||
|
||||
Config . groups . forEach { AppState . addGroup (it) }
|
||||
|
||||
var groups by mutableStateOf ( AppState . groups )
|
||||
AppState . subscribe { groups = it }
|
||||
val groups = mutableStateOf ( AppState . groups )
|
||||
AppState . subscribe { groups . value = it }
|
||||
|
||||
lifecycleScope . launch (IO) {
|
||||
val prefs = dataStore . data . firstOrNull ()
|
||||
|
@ -35,7 +38,7 @@ class MainActivity : EdgeToEdgeActivity () {
|
|||
setContent {
|
||||
AppFrame {
|
||||
Column ( Modifier . width ( 300 . dp ) ) {
|
||||
groups . forEach { group ->
|
||||
groups . value . forEach { group ->
|
||||
SceneSwitcher (group) { newScene ->
|
||||
AppState . setCurrentScene ( group . id , newScene )
|
||||
publishSceneChange ( group , newScene )
|
||||
|
@ -53,7 +56,7 @@ class MainActivity : EdgeToEdgeActivity () {
|
|||
|
||||
val currentScene = AppState . groups [0] . currentScene
|
||||
if ( currentScene != null ) lifecycleScope . launch (IO) {
|
||||
applicationContext . dataStore . edit {
|
||||
dataStore . edit {
|
||||
it [ stringPreferencesKey ("scene") ] = currentScene . name
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package com.kernelmaft.zanbur
|
||||
|
||||
import android.content.*
|
||||
import androidx.datastore.core.*
|
||||
import androidx.datastore.preferences.*
|
||||
import androidx.datastore.preferences.core.*
|
||||
|
||||
|
||||
|
||||
val Context . dataStore : DataStore <Preferences> by preferencesDataStore ("state")
|
Loading…
Add table
Reference in a new issue