developing apps for emerging markets

66
ONLINE-OFFLINE Developing Apps for Emerging Markets

Upload: annyce-davis

Post on 09-Feb-2017

259 views

Category:

Mobile


2 download

TRANSCRIPT

Page 1: Developing Apps for Emerging Markets

ONLINE-OFFLINEDeveloping Apps for Emerging Markets

Page 2: Developing Apps for Emerging Markets

OFF GRID ELECTRIC

From: https://medium.com/@Offgrid

Page 3: Developing Apps for Emerging Markets

OFF GRID ELECTRIC

Page 4: Developing Apps for Emerging Markets

AGENDA

ARCHITECTURELIBRARIES

CHALLENGES

Page 5: Developing Apps for Emerging Markets

ARCHITECTURE

Page 6: Developing Apps for Emerging Markets

BE USEFUL

My App ‣Store data locally ‣Separate UI and network ‣Queue requests

Page 7: Developing Apps for Emerging Markets

MVP(Model View Presenter)

Page 8: Developing Apps for Emerging Markets

EVENT BUS

DATABASE

REPOSITORY

REPOSITORY

ACTIVITY

FRAGMENT

JOBS

PRESENTER

PRESENTER

SERVICE

Page 9: Developing Apps for Emerging Markets

DISPLAY A VIEW

PRESENTER

SERVICE

ACTIVITY

EVENT BUS

DATABASEREPOSITORY

Page 10: Developing Apps for Emerging Markets

TAKE AN ACTION

PRESENTER

SERVICE

ACTIVITY

EVENT BUS

DATABASEREPOSITORY

JOB NETWORK

Page 11: Developing Apps for Emerging Markets

APP SERVER

Page 12: Developing Apps for Emerging Markets

AGREE ON

‣Conflict Resolution ‣Adding Timestamps to Requests ‣Bundling Requests ‣Use of Status Fields

Page 13: Developing Apps for Emerging Markets

EVENT BUS

DATABASE

REPOSITORY

REPOSITORY

ACTIVITY

FRAGMENT

JOBS

PRESENTER

PRESENTER

SERVICE

Page 14: Developing Apps for Emerging Markets

LIBRARIES

Page 15: Developing Apps for Emerging Markets

WHAT WE USE

‣Realm ‣EventBus ‣Android Job

Page 16: Developing Apps for Emerging Markets

STORE DATA LOCALLY

Page 17: Developing Apps for Emerging Markets

REALM

▸Easy to Set Up

▸Faster than ORMs

▸Has a Fluent API

Page 18: Developing Apps for Emerging Markets

REALM - MODEL CLASS

@RealmClasspublic class Place implements RealmModel{

}

Page 19: Developing Apps for Emerging Markets

REALM - MODEL CLASS

@RealmClasspublic class Place implements RealmModel{ @PrimaryKey private String localId;

@Index private Long remoteId;private Gps location; …

}

Page 20: Developing Apps for Emerging Markets

REALM - MODEL CLASS

localId remoteId location

19444498-2a40… 1458260

65031f36-bde9…

e85c9757-f546…

Page 21: Developing Apps for Emerging Markets

REALM - ADDING A RECORD

public class PlaceRepository implements Repository<Place> { @Override public void add (final Place item) {

}

Page 22: Developing Apps for Emerging Markets

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.copyToRealmOrUpdate( item ); } ); realm.close(); }

Page 23: Developing Apps for Emerging Markets

REALM - QUERY RESULT

private static final String PLACE_ID = "id";

@Overridepublic Place toResult (Realm realm){ return realm.where( Place.class )

}

Page 24: Developing Apps for Emerging Markets

REALM - QUERY RESULT

private static final String PLACE_ID = "id";

@Overridepublic Place toResult (Realm realm){ return realm.where( Place.class ) .equalTo( PLACE_ID, placeId ) .findFirst();}

Page 25: Developing Apps for Emerging Markets
Page 26: Developing Apps for Emerging Markets

SEPARATE UI AND NETWORK

Page 27: Developing Apps for Emerging Markets

EVENTBUS

From: http://greenrobot.org/eventbus

Page 28: Developing Apps for Emerging Markets

… WHEN YOU HAVE LOTS OF OBJECTS THAT ARE POTENTIAL EVENT SOURCES.

Martin Fowler

EVENTBUS

Page 29: Developing Apps for Emerging Markets

EVENTBUS - SETUP

@Provides @Singletonpublic Bus provideBus (){ return new Bus( EventBus.builder() .logNoSubscriberMessages( BuildConfig.DEBUG ) .throwSubscriberException( false ) .build() );}

Page 30: Developing Apps for Emerging Markets

EVENTBUS - REGISTER

public class LeadsMapPresenter { private final Bus bus; private LeadsMapView leadsMapView; @Inject LeadsMapPresenter (Bus bus) { this.bus = bus; } …

Page 31: Developing Apps for Emerging Markets

EVENTBUS - REGISTER

public class LeadsMapPresenter { public void attachView (LeadsMapView view) { this.leadsMapView = view; bus.register( this ); }

Page 32: Developing Apps for Emerging Markets

EVENTBUS - REGISTER

public class LeadsMapPresenter { public void attachView (LeadsMapView view) { this.leadsMapView = view; bus.register( this ); }

public void detachView () { this.leadsMapView = null; bus.unregister( this ); }

Page 33: Developing Apps for Emerging Markets

TAKE AN ACTION

PRESENTER

SERVICE

ACTIVITY

EVENT BUS

DATABASEREPOSITORY

JOB NETWORK

Page 34: Developing Apps for Emerging Markets

EVENTBUS - POST EVENT

api.submitPlace( place ).enqueue( new Callback<Place>(){

…JOB

Page 35: Developing Apps for Emerging Markets

EVENTBUS - POST EVENT

api.submitPlace( place ).enqueue( new Callback<Place>() { @Override public void onResponse (Call<Place> call, Response<Place> response) { if ( response.isSuccessful() ) { }

…JOB

Page 36: Developing Apps for Emerging Markets

EVENTBUS - POST EVENT

api.submitPlace( place ).enqueue( new Callback<Place>() { @Override public void onResponse (Call<Place> call, Response<Place> response) { if ( response.isSuccessful() ) { Place updatedPlace = response.body(); bus.post( new PlaceSubmissionSuccessEvent( updatedPlace ) ); }

…JOB

Page 37: Developing Apps for Emerging Markets

EVENTBUS - RETRIEVE EVENT

public class LeadsMapPresenter { @Subscribe public void onPlaceSubmissionSuccess (PlaceSubmissionSuccessEvent event) { leadsMapView.displaySuccessMessage( PLACE_SUCCESS ); }

PRESENTER

Page 38: Developing Apps for Emerging Markets
Page 39: Developing Apps for Emerging Markets

QUEUE REQUESTS

Page 40: Developing Apps for Emerging Markets

ANDROID JOB

Page 41: Developing Apps for Emerging Markets

ANDROID JOB

‣Alarm Manager

‣Job Scheduler

‣GCM Network Manager

Page 42: Developing Apps for Emerging Markets

ANDROID JOB

JOB MANAGER

JOB CREATOR

Page 43: Developing Apps for Emerging Markets

ANDROID JOB

JOB MANAGERPROVIDER

JOB

JOB CREATOR

PROVIDER

JOB

PROVIDER

JOB

Page 44: Developing Apps for Emerging Markets

ANDROID JOB

JOB MANAGERPROVIDER

JOB

JOB CREATOR

PROVIDER

JOB

PROVIDER

JOB

JOB REQUEST

Page 45: Developing Apps for Emerging Markets

ANDROID JOB

JOB MANAGERPROVIDER

JOB

JOB CREATOR

PROVIDER

JOB

PROVIDER

JOB

JOB REQUEST

JOB

Page 46: Developing Apps for Emerging Markets

ANDROID JOB - CREATOR

@Singletonpublic class ConfettiJobCreator implements JobCreator{ @Inject Map<String, Provider<Job>> jobs; @Override public Job create (String tag) {

}}

Page 47: Developing Apps for Emerging Markets

ANDROID JOB - CREATOR

@Singletonpublic class ConfettiJobCreator implements JobCreator { @Inject Map<String, Provider<Job>> jobs; @Override public Job create (String tag) { Provider<Job> jobProvider = jobs.get( tag ); return jobProvider.get(); }}

Page 48: Developing Apps for Emerging Markets

ANDROID JOB - JOB EXECUTION

@Overrideprotected Result onRunJob (final Params params){

} JOB

Page 49: Developing Apps for Emerging Markets

ANDROID JOB - JOB EXECUTION

@Overrideprotected Result onRunJob (final Params params) { PersistableBundleCompat extras = params.getExtras(); String placeId = extras.getString( PARAM_PLACE_ID );

} JOB

Page 50: Developing Apps for Emerging Markets

ANDROID JOB - JOB EXECUTION

@Overrideprotected Result onRunJob (final Params params) { PersistableBundleCompat extras = params.getExtras(); String placeId = extras.getString( PARAM_PLACE_ID ); if ( submitRequest( placeId ) ) { return Result.SUCCESS; } return Result.FAILURE;} JOB

Page 51: Developing Apps for Emerging Markets

ANDROID JOB

JOB MANAGERPROVIDER

JOB

JOB CREATOR

JOB REQUEST

JOB

Page 52: Developing Apps for Emerging Markets

ANDROID JOB - SCHEDULING

public static JobRequest buildJobRequest (String placeId) { PersistableBundleCompat extras = new PersistableBundleCompat(); extras.putString( PARAM_PLACE_ID, placeId );

}

Page 53: Developing Apps for Emerging Markets

ANDROID JOB - SCHEDULING

public static JobRequest buildJobRequest (String placeId) { PersistableBundleCompat extras = new PersistableBundleCompat(); extras.putString( PARAM_PLACE_ID, placeId ); return new JobRequest.Builder( SendPlaceRequestJob.JOB_TAG )

}

Page 54: Developing Apps for Emerging Markets

ANDROID JOB - SCHEDULING

public static JobRequest buildJobRequest (String placeId) { PersistableBundleCompat extras = new PersistableBundleCompat(); extras.putString( PARAM_PLACE_ID, placeId ); return new JobRequest.Builder( SendPlaceRequestJob.JOB_TAG ) .setExecutionWindow( 10_000L, 20_000L ) .setRequiredNetworkType( JobRequest.NetworkType.CONNECTED )

}

Page 55: Developing Apps for Emerging Markets

ANDROID JOB - SCHEDULING

public static JobRequest buildJobRequest (String placeId) { PersistableBundleCompat extras = new PersistableBundleCompat(); extras.putString( PARAM_PLACE_ID, placeId ); return new JobRequest.Builder( SendPlaceRequestJob.JOB_TAG ) .setExecutionWindow( 10_000L, 20_000L ) .setRequiredNetworkType( JobRequest.NetworkType.CONNECTED ) .setExtras( extras ) }

Page 56: Developing Apps for Emerging Markets

ANDROID JOB - SCHEDULING

public static JobRequest buildJobRequest (String placeId) { PersistableBundleCompat extras = new PersistableBundleCompat(); extras.putString( PARAM_PLACE_ID, placeId ); return new JobRequest.Builder( SendPlaceRequestJob.JOB_TAG ) .setExecutionWindow( 10_000L, 20_000L ) .setRequiredNetworkType( JobRequest.NetworkType.CONNECTED ) .setExtras( extras ) .setRequirementsEnforced( true ) .build(); }

Page 57: Developing Apps for Emerging Markets

ANDROID JOB - SCHEDULING

jobManager.schedule( );

Page 58: Developing Apps for Emerging Markets

ANDROID JOB - SCHEDULING

jobManager.schedule( SendPlaceRequestJob.buildJobRequest( id ) );

JOB REQUEST

JOB QUEUE

Page 59: Developing Apps for Emerging Markets

WHAT WE USE

‣Realm ‣EventBus ‣Android Job

Page 60: Developing Apps for Emerging Markets

CHALLENGES

Page 61: Developing Apps for Emerging Markets
Page 62: Developing Apps for Emerging Markets
Page 63: Developing Apps for Emerging Markets
Page 64: Developing Apps for Emerging Markets
Page 65: Developing Apps for Emerging Markets

WHAT’S NEXT?

‣RxJava ‣Mapbox ‣Push Notifications

Page 66: Developing Apps for Emerging Markets

THANKS

@brwngrldev

+AnnyceDavis

www.adavis.info