Type-safe reactive preferences for Android
OTHER License
Key concepts:
@Preferences(name = "temp")
public interface SomePreferences {
@Default(name = "name") String DEFAULT_VALUE = "DEFAULT_VALUE";
@Get(name = "name") Observable<String> getValueName();
@Set(name = "name") void setValue(String newValue);
...
@Contains Observable<Boolean> contains(String key);
@Delete void remove(String key);
}
Natively supported types are Boolean, Float, Integer, Long and String.
For everything else you have to extend IPreferenceAdapter and implement storing your entity via supported types. You can look at example of generic EnumAdapter. To include your adapter into processing just annotate it with @Adapter.
Each adapter should have a no-args constructor
For each parameter you have to always supply a default value as a field in an interface annotated with @Default. Type of parameter should be the same as in getter and setter.
Temp_Preferences preferences = new Temp_Preferences(new SharedPreferencesGatewayBuilder(contextRef));
Probably you'd store this in your dependency graph and inject it by interface For additional info look at the sample
Gradle:
repositories {
...
mavenCentral()
...
}
...
dependencies {
...
apt "com.malinskiy.sheldon2:compiler:$version"
compile "com.malinskiy.sheldon2:core:$version"
compile "com.malinskiy.sheldon2:gateway-sharedpreferences:$version"
...
}
Copyright 2017 Anton Malinskiy
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.