SimplePreferences


Source link: https://github.com/brunodles/AndroidSimplePreferences

SimplePreferences

A simple library to work with SharedPreferences.

How add it

On your build.gradle add the maven repository from jitpack.io


  repositories {

 maven {
 url "https://jitpack.io" 
}

}

On your project level ( app/build.gradle) add the androidSimplePreferences dependency.


  dependencies {

 compile 'com.github.brunodles:AndroidSimplePreferences:{
latest version
}
'

}

Now, you just need to run a GradleSync.

Choosing how to work with it

The first thing you need to do is create a new class.

There is two options, use it as a ActiveRecord where the object can save \ load \ clean itself. The problem is that you need to extend our class to make it work.
The other option, you can use a DAO to save many objects, this way you don't need to extend any class from the lib.

Using it as ActiveRecord

To use as an active record you just need to

  • Create your data class
  • Make it extends ActivePreferences
  • Annotate your persistant fields with @Property

This class is intent to be used when you have only one of this kind, like the current user data, the user preferences or even the app preferences.

Apply \ Reload \ Clean

To save the data as an activePreferences you just need to call apply().
To load the data you just need to call load().
To clean the data you just need to call clean().
That simple.

Fast sample

  public class CurrentUser extends ActivePreferences {

 @Property public String name;

 @Property public boolean isJedi = false;

}

 CurrentUser user = new CurrentUser()
user.name = "Anakin Skywalker";
// to save the current object on a preferences
user.apply();

// Reload the object
user.reload();

// Clean the preferences data.
user.clean();

Using it as Data Access Object

To use the DAO is simple too, you need to:

  • Create your data class
  • Annotate the persistant fields with @Property

Saving \ Loading \ Cleaning

To save the data with a Dao you just need to call dao.save(object, key).
To load the data you just need to call dao.load(emptyObject, key).
To clean the data you just need to call dao.clean(key).

Fast sample

  public class Person{

 @Property public String name;

 @Property public boolean isJedi = false;

}

 Person person = new Person()
person.name = "Anakin Skywalker";
// to save the current object on a preferences

// "this" is a context
DaoPreferences dao = new DaoPreferences(this)
// save the person with the key "anakin"

dao.save(person, "anakin");

 // load the person

person = dao.load(person, "anakin");

// clean the data

dao.clean("anakin");

Sample

You can see it in "pratice", it have some explanations too. On the sample you will see how to

  • Create a data class
  • Save data
  • load data

You can help this lib to grow

If you fond something wrong or if you want some feature, just create a issue or even better create a pull request with you idea.

Resources

Android library that allows a very easy-compatible Shelf View for smartphone and tablet.

Custom Toast on Android.

A RecyclerView that implements pull-to-refresh, load-more, and header features. You can use it like a standard RecyclerView.

Android Gmail API.

Sample Android application show how to set auto scroll in text view.

Moticons is a simple, easy and modern app to manage and use Japanese Emoticons.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes