At Off Grid Electric our mission is to power homes across rural Africa with affordable, solar energy. In order to do that we need to provide our employees with tools that work both on and offline. So how did we do it? In this talk, learn about the techniques we employed to provide a unique online-offline experience in our Android applications. We’ll discuss the overall architecture, third party libraries used, and some of the challenges that we faced. As more and more users come online in various parts of the world it makes sense for companies to begin exploring how they can modify their applications to be more network-friendly. This talk will get you headed in the right direction!
31. REALM - MODEL CLASS
@RealmClass
public class Place implements RealmModel {
}
32. REALM - MODEL CLASS
@RealmClass
public class Place implements RealmModel {
@PrimaryKey
private String localId;
@Index
private Long remoteId;
private Gps location;
…
}
33. REALM - MODEL CLASS
localId remoteId location
19444498-2a40… 1458260
65031f36-bde9…
e85c9757-f546…
34. REALM - ADDING A RECORD
public class PlaceRepository implements Repository<Place> {
@Override
public void add (final Place item) {
}
…
35. REALM - ADDING A RECORD
public class PlaceRepository implements Repository<Place> {
@Override
public void add (final Place item) {
Realm realm = Realm.getDefaultInstance();
realm.executeTransaction((realm) -> {
realm.insertOrUpdate(item);
});
realm.close();
}
…
36. REALM - QUERY RESULT
@Override
public Place toResult (Realm realm) {
return realm.where(Place.class)
}
37. REALM - QUERY RESULT
@Override
public Place toResult (Realm realm) {
return realm.where(Place.class)
.equalTo(PLACE_ID, placeId)
.findFirst();
}
38. REALM - QUERY RESULT
@Override
public Place toResult (Realm realm) {
return realm.where(Place.class)
.equalTo(PLACE_ID, placeId)
.findFirst();
}
52. EVENTBUS - SEND STATUS BAR NOTIFICATION
SERVICE
@Subscribe(priority = 1)
open fun onEvent(event: PaymentSuccessEvent) {
}
53. EVENTBUS - SEND STATUS BAR NOTIFICATION
SERVICE
@Subscribe(priority = 1)
open fun onEvent(event: PaymentSuccessEvent) {
val notif = getString(R.string.payment_submitted_message)
createNotification(notif, 1)
}