SharedPreferences + RxJava2 + SharedPreferences manager = Konohana
First, Define store interface annotated with @Store
and @Key
.
package com.github.hisaichi5518.konohana.example.store;
import android.support.annotation.Nullable;
import com.github.hisaichi5518.konohana.annotation.Key;
import com.github.hisaichi5518.konohana.annotation.Store;
@Store
interface User {
@Key
String name = "default name";
@Key
@Nullable
String bio = null;
}
Second, Run the Build > Rebuild Project
to generate Konohana classes, and instantiate a Konohana
class, which is generated by konohana processor.
// This is typically used as a singleton instance.
Konohana konohana = new Konohana(context);
// Create `name` preference.
konohana.storeOfUser().setName("hisaichi5518");
// Read `name` preference.
konohana.storeOfUser().getName();
// Update `name` preference.
konohana.storeOfUser().setName("new-hisaichi5518");
// Delete `name` preference.
konohana.storeOfUser().removeName();
// preferences has `name` ?
konohana.storeOfUser().hasName();
// Observe changes to `name` preference.
konohana.storeOfUser().nameAsObservable().subscribe(name -> {
// ...
});
boolean
String
float
int
long
Enum
Set<String>
Set<*>
List<*>
POJO
compile "com.github.hisaichi5518.konohana:konohana:0.3.0"
annotationProcessor "com.github.hisaichi5518.konohana:konohana-processor:0.3.0"
@Store(name = "your-xml-name", klass = "YourKonohana")
interface User {
@Key(name = "your-key-name")
String yourKey;
}
./gradlew bumpPatch
git checkout -b release/v`cat VERSION`
./gradlew clean build bintrayUpload -PbintrayUser=hisaichi5518 -PbintrayKey=... -PdryRun=false