diff --git a/jchucomponents-core/build.gradle b/jchucomponents-core/build.gradle index 2efa303f..791dfe49 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.0" + version = "1.7.1" } } } diff --git a/jchucomponents-ktx/build.gradle b/jchucomponents-ktx/build.gradle index 80e31721..ccc7674f 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.0" + version = "1.7.1" } } } diff --git a/jchucomponents-prefs/build.gradle b/jchucomponents-prefs/build.gradle index 6e4c4d68..07810930 100644 --- a/jchucomponents-prefs/build.gradle +++ b/jchucomponents-prefs/build.gradle @@ -59,8 +59,8 @@ afterEvaluate { release(MavenPublication) { from components.release groupId = "com.github.jeluchu" - artifactId = "jchucomponents-preferences" - version = "1.7.0" + artifactId = "jchucomponents-prefs" + version = "1.7.1" } } } 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 new file mode 100644 index 00000000..b6118888 --- /dev/null +++ b/jchucomponents-prefs/src/main/kotlin/com/jeluchu/prefs/datastore/DataStoreService.kt @@ -0,0 +1,71 @@ +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 9c9da0d2..19f45ff1 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.0" + version = "1.7.1" } } } diff --git a/jchucomponents-ui/build.gradle b/jchucomponents-ui/build.gradle index 51e8be58..75379b77 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.0" + version = "1.7.1" } } }