Skip to content

Commit e2f9573

Browse files
[Preferences DataStore] Update to alpha06
1 parent 91c5678 commit e2f9573

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

app/src/main/java/com/codelab/android/datastore/data/UserPreferencesRepository.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import android.util.Log
2121
import androidx.datastore.core.DataStore
2222
import androidx.datastore.preferences.SharedPreferencesMigration
2323
import androidx.datastore.preferences.core.Preferences
24+
import androidx.datastore.preferences.core.booleanPreferencesKey
2425
import androidx.datastore.preferences.core.edit
2526
import androidx.datastore.preferences.core.emptyPreferences
26-
import androidx.datastore.preferences.core.preferencesKey
27+
import androidx.datastore.preferences.core.stringPreferencesKey
2728
import androidx.datastore.preferences.createDataStore
2829
import kotlinx.coroutines.flow.Flow
2930
import kotlinx.coroutines.flow.catch
@@ -61,8 +62,8 @@ class UserPreferencesRepository private constructor(context: Context) {
6162

6263

6364
private object PreferencesKeys {
64-
val SORT_ORDER = preferencesKey<String>("sort_order")
65-
val SHOW_COMPLETED = preferencesKey<Boolean>("show_completed")
65+
val SORT_ORDER = stringPreferencesKey("sort_order")
66+
val SHOW_COMPLETED = booleanPreferencesKey("show_completed")
6667
}
6768

6869
/**
@@ -127,7 +128,7 @@ class UserPreferencesRepository private constructor(context: Context) {
127128
// time from another thread, we won't have conflicts
128129
dataStore.edit { preferences ->
129130
val currentOrder = SortOrder.valueOf(
130-
preferences[PreferencesKeys.SORT_ORDER] ?: SortOrder.NONE.name
131+
preferences[PreferencesKeys.SORT_ORDER] ?: SortOrder.NONE.name
131132
)
132133

133134
val newSortOrder =

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// Top-level build file where you can add configuration options common to all sub-projects/modules.
1818
buildscript {
19-
ext.kotlin_version = "1.4.10"
19+
ext.kotlin_version = "1.4.21"
2020
repositories {
2121
google()
2222
jcenter()
@@ -43,7 +43,7 @@ ext {
4343
constraintLayoutVersion = '2.0.2'
4444
coreVersion = '1.3.2'
4545
coroutinesVersion = '1.3.9'
46-
dataStoreVersion = '1.0.0-alpha04'
46+
dataStoreVersion = '1.0.0-alpha06'
4747
materialVersion = '1.2.1'
4848
lifecycleVersion = '2.2.0'
4949

0 commit comments

Comments
 (0)