mataku / konohana

SharedPreferences + RxJava2 + SharedPreferences manager = Konohana

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Konohana

SharedPreferences + RxJava2 + SharedPreferences manager = Konohana

Synopsis

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 -> {
  // ...
});

Support types

  • boolean
  • String
  • float
  • int
  • long
  • Enum
  • Set<String>
  • Set<*>
  • List<*>
  • POJO

Installation

compile "com.github.hisaichi5518.konohana:konohana:0.3.0"
annotationProcessor "com.github.hisaichi5518.konohana:konohana-processor:0.3.0"

Migration

@Store(name = "your-xml-name", klass = "YourKonohana")
interface User {
    @Key(name = "your-key-name")
    String yourKey;
}

Release

./gradlew bumpPatch
git checkout -b release/v`cat VERSION`
./gradlew clean build bintrayUpload -PbintrayUser=hisaichi5518 -PbintrayKey=... -PdryRun=false

About

SharedPreferences + RxJava2 + SharedPreferences manager = Konohana

License:Apache License 2.0


Languages

Language:Java 97.0%Language:Kotlin 3.0%