Compare commits
1 Commits
5be4981eb2
...
89279c0a0a
Author | SHA1 | Date | |
---|---|---|---|
89279c0a0a |
@ -1,8 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.library)
|
alias(libs.plugins.android.library)
|
||||||
alias(libs.plugins.kotlin.android)
|
alias(libs.plugins.kotlin.android)
|
||||||
alias(libs.plugins.hilt)
|
|
||||||
alias(libs.plugins.ksp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@ -32,17 +30,11 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
// AndroidX
|
// AndroidX
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
implementation(libs.androidx.appcompat)
|
implementation(libs.androidx.appcompat)
|
||||||
|
|
||||||
// Preferences data store
|
|
||||||
implementation(libs.preferencesDataStore)
|
|
||||||
|
|
||||||
// Hilt
|
|
||||||
implementation(libs.hilt.android)
|
|
||||||
ksp(libs.hilt.compiler)
|
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
testImplementation(libs.test.junit)
|
testImplementation(libs.test.junit)
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
package fr.openium.consentium.data.local
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.datastore.core.DataStore
|
|
||||||
import androidx.datastore.preferences.core.Preferences
|
|
||||||
import androidx.datastore.preferences.core.edit
|
|
||||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
|
||||||
import androidx.datastore.preferences.preferencesDataStore
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import kotlinx.coroutines.flow.firstOrNull
|
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import java.util.UUID
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
private val DATASTORE_NAME = "consentium_datastore"
|
|
||||||
|
|
||||||
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = DATASTORE_NAME)
|
|
||||||
|
|
||||||
internal class ConsentiumDataStore @Inject constructor(@ApplicationContext context: Context) {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
// Installation unique id
|
|
||||||
private val INSTALLATION_UNIQUE_ID = stringPreferencesKey("INSTALLATION_UNIQUE_ID")
|
|
||||||
}
|
|
||||||
|
|
||||||
private val _dataStore = context.dataStore
|
|
||||||
|
|
||||||
fun getInstallationUniqueId(): String =
|
|
||||||
runBlocking {
|
|
||||||
val uuid : String ? = _dataStore.data.map { prefs ->
|
|
||||||
prefs[INSTALLATION_UNIQUE_ID]
|
|
||||||
}.firstOrNull()
|
|
||||||
if (uuid == null) {
|
|
||||||
val newUuid = UUID.randomUUID().toString()
|
|
||||||
setInstallationUniqueId(newUuid)
|
|
||||||
newUuid
|
|
||||||
} else {
|
|
||||||
uuid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun setInstallationUniqueId(installationUniqueId: String) {
|
|
||||||
_dataStore.edit { prefs ->
|
|
||||||
prefs[INSTALLATION_UNIQUE_ID] = installationUniqueId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,7 +14,7 @@ appcompat = "1.7.0"
|
|||||||
lifecycle = "2.8.7"
|
lifecycle = "2.8.7"
|
||||||
|
|
||||||
# Hilt
|
# Hilt
|
||||||
hilt = "2.51.1"
|
hilt = "2.50"
|
||||||
hiltNavigation = "1.2.0"
|
hiltNavigation = "1.2.0"
|
||||||
|
|
||||||
# Compose
|
# Compose
|
||||||
@ -31,9 +31,6 @@ junit = "4.13.2"
|
|||||||
espressoCore = "3.6.1"
|
espressoCore = "3.6.1"
|
||||||
junitExtVersion = "1.2.1"
|
junitExtVersion = "1.2.1"
|
||||||
|
|
||||||
# Preferences DataStore
|
|
||||||
preferencesDataStore = "1.1.1"
|
|
||||||
|
|
||||||
# Plugins
|
# Plugins
|
||||||
agp = "8.7.3"
|
agp = "8.7.3"
|
||||||
kotlin = "2.0.0"
|
kotlin = "2.0.0"
|
||||||
@ -64,7 +61,7 @@ androidx-lifecycle-compose = { group = "androidx.lifecycle", name = "lifecycle-r
|
|||||||
|
|
||||||
# Hilt
|
# Hilt
|
||||||
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
|
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
|
||||||
hilt-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
|
hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt" }
|
||||||
hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hiltNavigation" }
|
hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hiltNavigation" }
|
||||||
|
|
||||||
# Timber
|
# Timber
|
||||||
@ -91,9 +88,6 @@ androidx-navigation-common-ktx = { group = "androidx.navigation", name = "naviga
|
|||||||
androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationCompose" }
|
androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationCompose" }
|
||||||
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
|
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
|
||||||
|
|
||||||
# Preferences DataStore
|
|
||||||
preferencesDataStore = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "preferencesDataStore" }
|
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
test-junit = { group = "junit", name = "junit", version.ref = "junit" }
|
test-junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||||
test-androidx-junit = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junitExtVersion" }
|
test-androidx-junit = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junitExtVersion" }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user