add the library from maven central like this in build.gradle.kts
and sync project
dependencies {
implementation("com.naulian:keeper:0.1.0-alpha01")
}
val keeper = Keeper(context.datastore)
//or you can just inject it
class YourClass @Inject constructor(private val keeper : Keeper)
call inside a coroutine scope
viewModelScope.launch {
keeper.keepString(key, "value")
keeper.keepInt(key, 0)
keeper.keepBoolean(key, true)
keeper.keep(key, User(name = "John")) //data class need to be annotated with @Serializable
}
val string = keeper.recallString(key) //default value is ""
val string2 = keeper.recallString(key, "Username") //custom default value
val float = keeper.recallFloat(key, 1f)
viewModelScope.launch {
repeat(5){
keeper.keepInt(key, it)
delay(1000)
}
}
viewModelScope.launch {
keeper.recallIntAsFlow(key) { //collecting
print(it)
}
}
//output 01234