Fit storage bean for SharedPreferences which uses annotation processing to generate boilerplate code for you.
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add the following dependency to your build.gradle
file:
dependencies {
implementation 'com.github.2tu.fit:fit:1.2.3'
annotationProcessor 'com.github.2tu.fit:fit-compiler:1.2.3'
}
annotation model class.
@SharedPreferenceAble
save object
User user = new User();
Fit.save(context, user);
Fit.save(context, "user", user);
get
User user = Fit.get(context, User.class);
User user = Fit.get(context, "user", User.class);
clear
Fit.clear(context, User.class);
Fit.clear(context, User.class, "user");
other
Fit.get(context, "name").getBoolean("isFirst", false);
SharedPreferences.Editor editor = Fit.edit(context, "name");
editor.putBoolean("isFirst", true);
editor.apply();
Fit.clearObjectField(cotext, "user", "hobbies");
Copyright 2016 Tu
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.