Skip to content

nikolai-manzhos/PreferencesHelper

Repository files navigation

PreferencesHelper

Build Status codecov

Getting started

In app build.gradle:

dependencies {
    implementation 'com.nikolaymanzhos:preferenceshelper:2.4'
}

Setup library in Application class:

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        PreferencesHelper.builder(this)
                .build();
    }
}

Bonus

Ability to store List<String>.
Just call PreferencesHelper#putStringList and you are good to go!

Usage

After PreferencesHelper has been initialized you can access preferences from any place.
Just call PreferencesHelper.getInstance().

To keep all preferences in single place create new class and extend it form DefaultPreferencesManager class. Inside your new class you'll have access to preferences by calling getPreferencesHelper() method.

Advanced

Set custom properties for your preference storage.

PreferencesHelper.builder(this)
        .setMode(ContextWrapper.MODE_PRIVATE)
        .setName("MyPrefs")
        .build();