reminder


Source link: https://github.com/OneCodeLabs/reminder

reminder

reminder lets you persist the state of your views to recover them later in order to display old data until fresh data arrives.

Usage

Initialize Reminder:

public class MyApplication extends Application {

  @Override
  public void onCreate() {

super.onCreate();

...

Reminder.init(this);

  
}
 
}
 

Implement Remindable:

public class MainActivity extends AppCompatActivity implements Remindable {

@Override
  protected void onCreate(Bundle savedInstanceState) {

...

// This call results in either a call to onSnapshotAvailable() or onSnapshotNotFound().

Reminder.remind(this);

  
}

@Override
  public void saveSnapshot(ReminderBundle snapshot) {

// Save the current state of this Remindable into the snapshot.

// The snapshot is used as follows: snapshot.put(KEY, object);


// Information inside ReminderBundle is saved as key-value pairs.

// This method will be called automatically (if this is an Activity) by the 

// time onStop() is called.

// In case your Remindable is not an Activity, an explicit call to 

// Reminder.save(this) should be made by the time the Remindable is about

// to be stopped/destroyed.
  
}

@Override
  public void onSnapshotAvailable(ReminderBundle snapshot) {

// A snapshot for this Remindable is available.

// The snapshot is used as follows: snapshot.get(KEY, clazz).

// KEY is a String and clazz the Class<> instance of that particular object.

// snapshot.isMillisecondsOld(N) returns true if the snapshot is at

// least N milliseconds old.

// This snapshot can be used to populate this Remindable and

// decide according to some criteria (e.g: snapshot.isMillisecondsOld(TIME_LIMIT))

// if newer data should be fetched
  
}

@Override
  public void onSnapshotNotFound() {

// No snapshot was available for this Remindable.

// Time to fetch new data!
  
}
 
}
 

RemindableWithId

If you want to persist the same Remindable multiple times according to some id value, you can implement RemindableWithId instead, which will make you implement one extra method called remindableId().

public class ItemDetailFragment extends Fragment implements RemindableWithId {

@Override
  public void onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

...

// This call results in either a call to onSnapshotAvailable() or onSnapshotNotFound().

Reminder.remind(this);

  
}

 @Override
  public String remindableId() {

// return something that identifies this item.
  
}

 @Override
  public void onStop() {

// Since this is not an Activity, an explicit call to Reminder.save(this) must be made.

Reminder.save(this);

super.onStop();

  
}

@Override
  public void saveSnapshot(ReminderBundle snapshot) {

// Same as before.
  
}

@Override
  public void onSnapshotAvailable(ReminderBundle snapshot) {

// Same as before.
  
}

@Override
  public void onSnapshotNotFound() {

// Same as before.
  
}
 
}
 

Persistance Modes

Reminder can be configured to use SharedPreferences or SQLite as persistence modes. SQLite is the default mode. This is an example of how to configure it to use SharedPreferences:

public class MyApplication extends Application {

  @Override
  public void onCreate() {

super.onCreate();

...

ReminderConfig config = new ReminderConfig.Builder()

  .useSharedPreferences()

  .build();

Reminder.init(this, config);

  
}
 
}
 

Data clearing

If you made an update to your data model or want to delete the saved information for whatever reason, there's a simple way to do so:

public class MyApplication extends Application {

  @Override
  public void onCreate() {

super.onCreate();

Reminder.init(this);

...

Reminder.deleteAll();

  
}
 
}
 

Download

Add the JitPack repository to your root build.gradle:

 allprojects {

repositories {

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

}
  
}

Add the Gradle dependency:

 dependencies {

compile 'com.github.OneCodeLabs:reminder:x.y.z@aar'  
}

License

The MIT License (MIT)  Copyright (c) 2016
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

Library to validate username, email and passwords.

A GitHub third party client, show the rank of users and repositories, trending.

The android library that provides a simple and customizable NumberPicker.

When Android's Pair class is just not enough.

Android library that provides a simple way of make user discovering your apps when he first opens it.

OneKey Android Studio generate proguard codes.

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