-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added Jetpack DataStore support - Refactored some general configurations
- Loading branch information
1 parent
47062c3
commit b0baa7d
Showing
78 changed files
with
588 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# About | ||
|
||
The DataStore library stores data asynchronously, consistently, and transactionally, overcoming some of the drawbacks of SharedPreferences. | ||
|
||
# Links | ||
|
||
- [Official Site](https://developer.android.com/kotlin/multiplatform/datastore) | ||
- [Integration Guide](https://developer.android.com/kotlin/multiplatform/datastore#creating-datastore) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Usage | ||
|
||
## Overview | ||
|
||
The API can be accessed through: | ||
- `shared.data.source.keyvalue.KeyValueSource` - base class at the core module level. | ||
- `shared.data.source.keyvalue.DataStoreSource` - implementation of the base class. | ||
|
||
**KeyValueSource** provides the following methods: | ||
|
||
- `read(key: String): T?` - Reads data of type [T] associated with the given [key]. | ||
- `save(key: String, value: T)` - Saves the provided [value] of type [T] with the given [key]. | ||
- `read(key: String, serializationStrategy: SerializationStrategy<T>): T?` - Reads the value associated with the specified key. | ||
- `save(key: String, value: T, serializationStrategy: SerializationStrategy<T>): T` - Saves the specified key-value pair. | ||
- `remove(key: String, serializationStrategy: SerializationStrategy<T>): T?` - Removes the value associated with the specified key. | ||
- `clear()` - Clears all key-value pairs. | ||
|
||
## Example | ||
|
||
Class instance is pre-configured via dependency injection (DI) as a singleton in `app.factory.configureKoin`. | ||
|
||
To start using, just inject it to your DI managed class. | ||
|
||
```kotlin | ||
class TemplateViewModel @Inject constructor( | ||
private val keyValueSource: KeyValueSource | ||
) : BaseViewModel() { | ||
|
||
override fun doBind() { | ||
launchAsync("init settings") { | ||
... | ||
val passcode: String? = keyValueSource.read("name") | ||
... | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
apply from: "${project.rootDir}/gradle/kotlin/processor.gradle" | ||
|
||
group = 'com.kotlitecture.kotli' | ||
version = '0.6.0' | ||
version = '0.7.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...n/kotlin/kotli/template/multiplatform/compose/common/CommonStatelyCollectionsProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package kotli.template.multiplatform.compose.common | ||
|
||
import kotli.engine.BaseFeatureProcessor | ||
import kotli.engine.FeatureProcessor | ||
import kotli.engine.TemplateState | ||
import kotli.engine.template.VersionCatalogRules | ||
import kotli.engine.template.rule.CleanupMarkedLine | ||
import kotli.engine.template.rule.RemoveMarkedLine | ||
import kotli.template.multiplatform.compose.Rules | ||
|
||
object CommonStatelyCollectionsProcessor : BaseFeatureProcessor() { | ||
|
||
override fun getId(): String = "common.stately-collections" | ||
override fun isInternal(): Boolean = true | ||
|
||
override fun dependencies(): List<Class<out FeatureProcessor>> = listOf( | ||
CommonStatelyProcessor::class.java | ||
) | ||
|
||
override fun doApply(state: TemplateState) { | ||
state.onApplyRules( | ||
Rules.BuildGradleSharedData, | ||
CleanupMarkedLine("{common.stately-collections}") | ||
) | ||
} | ||
|
||
override fun doRemove(state: TemplateState) { | ||
state.onApplyRules( | ||
Rules.BuildGradleSharedData, | ||
RemoveMarkedLine("{common.stately-collections}") | ||
) | ||
state.onApplyRules( | ||
VersionCatalogRules( | ||
RemoveMarkedLine("stately-concurrent-collections") | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...in/kotli/template/multiplatform/compose/dataflow/keyvalue/datastore/DataStoreProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package kotli.template.multiplatform.compose.dataflow.keyvalue.datastore | ||
|
||
import kotli.engine.BaseFeatureProcessor | ||
import kotli.engine.FeatureProcessor | ||
import kotli.engine.FeatureTag | ||
import kotli.engine.TemplateState | ||
import kotli.engine.template.VersionCatalogRules | ||
import kotli.engine.template.rule.CleanupMarkedLine | ||
import kotli.engine.template.rule.RemoveFile | ||
import kotli.engine.template.rule.RemoveMarkedLine | ||
import kotli.template.multiplatform.compose.Rules | ||
import kotli.template.multiplatform.compose.Tags | ||
import kotli.template.multiplatform.compose.dataflow.keyvalue.common.CommonKeyValueProcessor | ||
import kotli.template.multiplatform.compose.platform.client.MobileAndDesktopProcessor | ||
import kotli.template.multiplatform.compose.platform.client.android.AndroidPlatformProcessor | ||
import kotli.template.multiplatform.compose.platform.client.ios.IOSPlatformProcessor | ||
import kotli.template.multiplatform.compose.platform.client.jvm.JvmPlatformProcessor | ||
import kotlin.time.Duration.Companion.hours | ||
|
||
object DataStoreProcessor : BaseFeatureProcessor() { | ||
|
||
const val ID = "dataflow.keyvalue.datastore" | ||
|
||
override fun getId(): String = ID | ||
override fun getTags(): List<FeatureTag> = Tags.MobileAndDesktop | ||
override fun getWebUrl(state: TemplateState): String = | ||
"https://developer.android.com/kotlin/multiplatform/datastore" | ||
|
||
override fun getIntegrationUrl(state: TemplateState): String = | ||
"https://developer.android.com/kotlin/multiplatform/datastore#creating-datastore" | ||
|
||
override fun getIntegrationEstimate(state: TemplateState): Long = 2.hours.inWholeMilliseconds | ||
|
||
override fun canApply(state: TemplateState): Boolean { | ||
return listOfNotNull( | ||
state.getFeature(AndroidPlatformProcessor.ID), | ||
state.getFeature(IOSPlatformProcessor.ID), | ||
state.getFeature(JvmPlatformProcessor.ID) | ||
).isNotEmpty() | ||
} | ||
|
||
override fun dependencies(): List<Class<out FeatureProcessor>> = listOf( | ||
MobileAndDesktopProcessor::class.java, | ||
CommonKeyValueProcessor::class.java, | ||
) | ||
|
||
override fun doApply(state: TemplateState) { | ||
state.onApplyRules( | ||
Rules.BuildGradleSharedData, | ||
CleanupMarkedLine("{dataflow.keyvalue.datastore}") | ||
) | ||
} | ||
|
||
override fun doRemove(state: TemplateState) { | ||
state.onApplyRules( | ||
Rules.DataStoreSource, | ||
RemoveFile() | ||
) | ||
state.onApplyRules( | ||
Rules.ConfigureKoinDI, | ||
RemoveMarkedLine("DataStoreSource"), | ||
RemoveMarkedLine("KeyValueSource"), | ||
) | ||
state.onApplyRules( | ||
Rules.BuildGradleSharedData, | ||
RemoveMarkedLine("{dataflow.keyvalue.datastore}") | ||
) | ||
state.onApplyRules( | ||
VersionCatalogRules( | ||
RemoveMarkedLine("androidx-datastore") | ||
) | ||
) | ||
state.onApplyRules( | ||
"*/createDataStorePath.kt", | ||
RemoveFile() | ||
) | ||
} | ||
|
||
} |
Oops, something went wrong.