Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
feat: remove KVStorage "state" singleton, and replace it with ad-hoc …
Browse files Browse the repository at this point in the history
…KVStorage instances (#116)
  • Loading branch information
Matteo Battaglio authored May 29, 2020
1 parent 3cc9f7f commit d866417
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
32 changes: 23 additions & 9 deletions app/src/main/java/it/ministerodellasalute/immuni/koinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ import org.koin.dsl.module
* Dependency Injection Koin module.
*/
val appModule = module {

/**
* KVStorage to store generic non-database data encrypted using AES256.
*/
single { KVStorage("state", androidContext(), encrypted = true, moshi = get()) }

/**
* App Configuration Service APIs
*/
Expand Down Expand Up @@ -132,7 +126,12 @@ val appModule = module {

single {
ConfigurationSettingsStoreRepository(
get(),
KVStorage(
name = "ConfigurationSettingsStoreRepository",
context = androidContext(),
encrypted = true,
moshi = get()
),
defaultSettings
)
}
Expand Down Expand Up @@ -174,7 +173,14 @@ val appModule = module {
}

single {
UploadDisablerStore(get())
UploadDisablerStore(
KVStorage(
name = "UploadDisablerStore",
context = androidContext(),
encrypted = true,
moshi = get()
)
)
}

single {
Expand Down Expand Up @@ -229,7 +235,15 @@ val appModule = module {
}

single {
UserRepository(get())
UserRepository(
KVStorage(
name = "UserRepository",
context = androidContext(),
encrypted = true,
moshi = immuniMoshi
)

)
}

single {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class KVStorage(
val name: String,
context: Context?,
val cacheInMemory: Boolean = true,
val encrypted: Boolean,
val encrypted: Boolean = true,
val moshi: Moshi,
// The following two properties should be private but are not, because they're used in public
// inline methods, thus the underscore prefix.
Expand All @@ -67,7 +67,7 @@ class KVStorage(
mutableMapOf()

/**
* Checks if the storage contains the given key.
* Checks if the storage contains the given [key].
*/
fun <T : Any> contains(key: Key<T>): Boolean = synchronized(this) {
_cache.contains(key) || _sharedPrefs.contains(key.name)
Expand All @@ -85,8 +85,8 @@ class KVStorage(
}

/**
* Saves value for the given key. If value's type is not one of the supported primitive types
* (Boolean, Int, Long, Float, String), it first serializes value to Json with Moshi
* Saves [value] for the given [key]. If value's type is not one of the supported primitive types
* (Boolean, Int, Long, Float, String), it first serializes value to Json with [Moshi]
* and then saves it as a String.
*/
inline operator fun <reified T : Any> set(key: Key<T>, value: T) = synchronized(this) {
Expand Down

0 comments on commit d866417

Please sign in to comment.