Multipreference

Additional

Language
Kotlin
Version
0.3.1 (Dec 11, 2017)
Created
Nov 6, 2017
Updated
Dec 11, 2017
Owner
Jumpei Matsuda (jmatsu)
Contributor
Jumpei Matsuda (jmatsu)
1
Activity
Badge
Generate
Download
Source code

Show card

Multipreference

Multipreference provides an annotation-based Key-Value store for Android development.

  • Reflection-free
  • Support Map-based in-memory data store
  • Support SharedPreferences-based data store
  • Support flavor-based default value configurations

Usage

You need to create a class which will have Key-Value definitions, and prepare each Key-Value definitions which are represented by fields.

import com.github.jmatsu.multipreference.Key;
import com.github.jmatsu.multipreference.Preference;

@Preference
class KeyValueDefinitions {
    @Key
    static final int value = 0x01;
}
  • The class must have com.github.jmatsu.multipreference.Preference.
  • The class must not be private.
  • Basically private fields are NOT allowed.

This library will generates a class KeyValueDefinitionsPreference and Key-Value API like below.

private static final String VALUE = "value";

public int getValue() {
    return dataStore.getInt(VALUE, KeyValueDefinitions.value);
}

public void setValue(int value) {
    dataStore.setInt(VALUE, value);
}

You can use this class by calling KeyValueDefinitionsPreference.inMemory() or KeyValueDefinitionsPreference.sharedPreference(context, preferencesName).

You can see more examples in sample module's source and testcases.

Especially for flavor-based configurations, you can check from:

Download

The latest version :

You need to add the following to build.gradle of android-application module or android-library module. This library is available on jcenter.

repositories {
    maven {
        jcenter()
    }
}

ext.multipreferenceVersion = '[latest_version]'

dependencies {
  implementation "com.github.jmatsu:multipreference:${multipreferenceVersion}"
  annotationProcessor "com.github.jmatsu:multipreference-processor:${multipreferenceVersion}"
}

Issue Tracker

Use Github Issues of this repository. multipreference/issues

LICENSE

 Copyright 2017 Jumpei Matsuda

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.