Holocrons are ancient repositories of knowledge and wisdom that can only be accessed by those skilled in the Force.
Step 1.: Add JitPack in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.nzkozar:holocron:v1.0.5@aar'
compile 'com.google.code.gson:gson:2.8.0'
}
//Init Holocron. This will take few seconds to execute, as it must build encryption resources.
Holocron holocron = new Holocron(context);
or
//Init Holocron asynchronously and get notified through a HolocronInitListener interface when Holocron is ready.
Holocron holocron = new Holocron(context, new HolocronInitListener() {
@Override
public void onHolocronInitComplete() {
//Holocron can now be used
}
});
//save an object of any Class that extends Object
holocron.put(object, (long)object.getId());
//retrieve a single stored object of a class using an id. Returns null if no object matches both class and id
Checkpoint checkpoint = holocron.get(Checkpoint.class,(long)id);
//retrieve all objects stored using the provided Class
List<Checkpoint> checkpoints = holocron.getAll(Checkpoint.class);
//retrieve asynchronously all objects stored using the provided Class
holocron.getAllAsync(Checkpoint.class, new HolocronResponseHandler<Checkpoint>() {
@Override
public void onHolocronResponse(int responseCode, HolocronResponse<Checkpoint> response) {
List<Checkpoint> checkpoints = data.getDataObjectList());
}
});
//delete an object from storage
boolean deleted = holocron.remove(Checkpoint.class,(long)id);
//delete all objects of a provided Class from storage
boolean deleted = holocron.remove(Checkpoint.class);
//delete asynchronously all objects of a provided Class from storage
holocron.removeAllAsync(Checkpoint.class, new HolocronResponseHandler() {
@Override
public void onHolocronResponse(int responseCode, HolocronResponse response) {
//Objects deleted
}
});
The accompanying example shows the adding, displaying and removing of Checkpoint class objects.
public class Checkpoint{
private long id;
private String name;
private double longitude,latitude;
}
All data is encrypted using AES encryption.
This library uses Gson to convert objects, so any object convertable by Gson can be stored with Holocron.