From 3870db1c88221e2cfc571399ee8f0f90ceda2cef Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 14 Sep 2022 22:47:57 +0600 Subject: [PATCH] fix of #155 and build --- CHANGELOG.md | 3 +++ koin/build.gradle | 5 +++++ .../inmo/micro_utils/repos/keyvalue/KeyValueStore.kt | 12 +++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 167067c2d2f..778de2ec70a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ * Add opportunity to use markers in actors (solution of [#160](https://github.com/InsanusMokrassar/MicroUtils/issues/160)) * `Koin`: * Module inited :) +* `Repos`: + * `Android`: + * Add typealias `KeyValueSPRepo` and opportunity to create shared preferences `KeyValue` repo with `KeyValueStore(...)` (fix of [#155](https://github.com/InsanusMokrassar/MicroUtils/issues/155)) ## 0.12.12 diff --git a/koin/build.gradle b/koin/build.gradle index d6b3efd2031..ecb3b5dcc29 100644 --- a/koin/build.gradle +++ b/koin/build.gradle @@ -19,5 +19,10 @@ kotlin { api libs.kt.reflect } } + androidMain { + dependencies { + api libs.kt.reflect + } + } } } diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt index ccbc93fe0b7..1e5dda1a78f 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt @@ -17,7 +17,7 @@ fun Context.keyValueStore( ): KeyValueRepo { @Suppress("UNCHECKED_CAST") return cache.getOrPut(name) { - KeyValueStore(this, name, cacheValues) + KeyValueStore(c = this, preferencesName = name, useCache = cacheValues) } as KeyValueStore } @@ -149,6 +149,14 @@ class KeyValueStore internal constructor ( _onValueRemovedFlow.emit(it) } } + + companion object { + operator fun invoke( + context: Context, + name: String = "default", + cacheValues: Boolean = false + ) = context.keyValueStore(name, cacheValues) + } } inline fun SharedPreferencesKeyValueRepo( @@ -156,3 +164,5 @@ inline fun SharedPreferencesKeyValueRepo( name: String = "default", cacheValues: Boolean = false ) = context.keyValueStore(name, cacheValues) + +typealias KeyValueSPRepo = KeyValueStore