diff --git a/jchucomponents-core/build.gradle b/jchucomponents-core/build.gradle index 791dfe49..efda0b49 100644 --- a/jchucomponents-core/build.gradle +++ b/jchucomponents-core/build.gradle @@ -77,7 +77,7 @@ afterEvaluate { from components.release groupId = "com.github.jeluchu" artifactId = "jchucomponents-core" - version = "1.7.1" + version = "1.7.2" } } } diff --git a/jchucomponents-ktx/build.gradle b/jchucomponents-ktx/build.gradle index ccc7674f..5cc77323 100644 --- a/jchucomponents-ktx/build.gradle +++ b/jchucomponents-ktx/build.gradle @@ -64,7 +64,7 @@ afterEvaluate { from components.release groupId = "com.github.jeluchu" artifactId = "jchucomponents-ktx" - version = "1.7.1" + version = "1.7.2" } } } diff --git a/jchucomponents-prefs/build.gradle b/jchucomponents-prefs/build.gradle index 138cc9a7..f8b3001d 100644 --- a/jchucomponents-prefs/build.gradle +++ b/jchucomponents-prefs/build.gradle @@ -63,7 +63,7 @@ afterEvaluate { from components.release groupId = "com.github.jeluchu" artifactId = "jchucomponents-prefs" - version = "1.7.1" + version = "1.7.2" } } } diff --git a/jchucomponents-prefs/src/main/kotlin/com/jeluchu/prefs/datastore/DataStoreHelpers.kt b/jchucomponents-prefs/src/main/kotlin/com/jeluchu/prefs/datastore/DataStoreHelpers.kt index 9b9bdf12..5ff17555 100644 --- a/jchucomponents-prefs/src/main/kotlin/com/jeluchu/prefs/datastore/DataStoreHelpers.kt +++ b/jchucomponents-prefs/src/main/kotlin/com/jeluchu/prefs/datastore/DataStoreHelpers.kt @@ -8,7 +8,13 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.platform.LocalContext import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.booleanPreferencesKey +import androidx.datastore.preferences.core.doublePreferencesKey import androidx.datastore.preferences.core.edit +import androidx.datastore.preferences.core.floatPreferencesKey +import androidx.datastore.preferences.core.intPreferencesKey +import androidx.datastore.preferences.core.longPreferencesKey +import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.jeluchu.prefs.extensions.empty @@ -117,6 +123,13 @@ class DataStoreHelpers { dataStore = context.defaultPreferencesDataStore } + fun intPrefsKey(name: String) = intPreferencesKey(name) + fun floatPrefsKey(name: String) = floatPreferencesKey(name) + fun longPrefsKey(name: String) = longPreferencesKey(name) + fun doublePrefsKey(name: String) = doublePreferencesKey(name) + fun stringPrefsKey(name: String) = stringPreferencesKey(name) + fun booleanPrefsKey(name: String) = booleanPreferencesKey(name) + fun DataStore.getValueSync( key: Preferences.Key ) = runBlocking { data.first() }[key] diff --git a/jchucomponents-prefs/src/main/kotlin/com/jeluchu/prefs/datastore/DataStoreService.kt b/jchucomponents-prefs/src/main/kotlin/com/jeluchu/prefs/datastore/DataStoreService.kt deleted file mode 100644 index b6118888..00000000 --- a/jchucomponents-prefs/src/main/kotlin/com/jeluchu/prefs/datastore/DataStoreService.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.jeluchu.prefs.datastore - -import androidx.datastore.preferences.core.Preferences -import androidx.datastore.preferences.core.booleanPreferencesKey -import androidx.datastore.preferences.core.doublePreferencesKey -import androidx.datastore.preferences.core.floatPreferencesKey -import androidx.datastore.preferences.core.intPreferencesKey -import androidx.datastore.preferences.core.longPreferencesKey -import androidx.datastore.preferences.core.stringPreferencesKey - -class DataStoreService { - private val preferences by lazy { DataStoreHelpers() } - - fun savePreference( - tag: Preferences.Key, - value: T - ) = preferences.savePreference(tag, value) - - fun savePreference( - tag: Preferences.Key, - value: Int - ) = preferences.savePreference(tag, value) - - fun savePreference( - tag: Preferences.Key, - value: Long - ) = preferences.savePreference(tag, value) - - fun savePreference( - tag: Preferences.Key, - value: String - ) = preferences.savePreference(tag, value) - - fun savePreference( - tag: Preferences.Key, - value: Boolean - ) = preferences.savePreference(tag, value) - - fun getPreference( - tag: Preferences.Key - ) = preferences.getPreference(tag) - - fun getPreference( - tag: Preferences.Key, - default: Int - ) = preferences.getPreference(tag, default) - - fun getPreference( - tag: Preferences.Key, - default: Long - ) = preferences.getPreference(tag, default) - - fun getPreference( - tag: Preferences.Key, - default: String - ) = preferences.getPreference(tag, default) - - fun getPreference( - tag: Preferences.Key, - default: Boolean - ) = preferences.getPreference(tag, default) - - companion object { - fun intPrefsKey(name: String) = intPreferencesKey(name) - fun floatPrefsKey(name: String) = floatPreferencesKey(name) - fun longPrefsKey(name: String) = longPreferencesKey(name) - fun doublePrefsKey(name: String) = doublePreferencesKey(name) - fun stringPrefsKey(name: String) = stringPreferencesKey(name) - fun booleanPrefsKey(name: String) = booleanPreferencesKey(name) - } -} \ No newline at end of file diff --git a/jchucomponents-qr/build.gradle b/jchucomponents-qr/build.gradle index 19f45ff1..646509d7 100644 --- a/jchucomponents-qr/build.gradle +++ b/jchucomponents-qr/build.gradle @@ -59,7 +59,7 @@ afterEvaluate { from components.release groupId = "com.github.jeluchu" artifactId = "jchucomponents-qr" - version = "1.7.1" + version = "1.7.2" } } } diff --git a/jchucomponents-ui/build.gradle b/jchucomponents-ui/build.gradle index 75379b77..d0fbd889 100644 --- a/jchucomponents-ui/build.gradle +++ b/jchucomponents-ui/build.gradle @@ -66,7 +66,7 @@ afterEvaluate { from components.release groupId = "com.github.jeluchu" artifactId = "jchucomponents-ui" - version = "1.7.1" + version = "1.7.2" } } }