The android past · present · future#

9f523401a845a29c93ff73cde4c3db2b?s=47 Erik Jhordan Rey
April 21, 2016
580

The android past · present · future#

GDG Open Lima hangouts, April 2016

9f523401a845a29c93ff73cde4c3db2b?s=128

Erik Jhordan Rey

April 21, 2016
Tweet

Transcript

  1. None
  2. None
  3. • • •

  4. None
  5. • • •

  6. None
  7. None
  8. None
  9. None
  10. None
  11. None
  12. Model View Presenter View Presenter Model User interaction notify user

    event request data Update UI with entities delivers entities
  13. Kata

  14. MVP Example

  15. public interface ArtistsMvpView extends MvpView{ void showLoading(); void hideLoading(); void

    showArtistNotFoundMessage(); void showConnectionErrorMessage(); void renderArtists(List<Artist> artists); void launchArtistDetail(Artist artist); } View
  16. public class ArtistsPresenter implements Presenter<ArtistsMvpView>, ArtistCallback { private ArtistsMvpView artistsMvpView;

    private ArtistsInteractor artistsInteractor; public ArtistsPresenter() { } @Override public void setView(ArtistsMvpView view) { if (view == null) throw new IllegalArgumentException("You can't set a null view"); artistsMvpView = view; artistsInteractor = new ArtistsInteractor(artistsMvpView.getContext()); } @Override public void detachView() { artistsMvpView = null; } public void onSearchArtist(String string) { artistsMvpView.showLoading(); artistsInteractor.loadDataFromApi(string, this); } public void launchArtistDetail(Artist artist) { artistsMvpView.launchArtistDetail(artist); } //more methods } Presenter
  17. Interactor public class ArtistsInteractor { public void loadDataFromApi(String query, ArtistCallback

    artistCallback) { mSpotifyService.searchArtist(query) .subscribeOn(mSpotifyApp.SubscribeScheduler()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(ArtistsSearch -> onSuccess(ArtistsSearch, artistCallback), throwable -> onError(throwable, artistCallback)); } // more methods }
  18. User interaction public void onSearchArtist(String string) { artistsMvpView.showLoading(); artistsInteractor.loadDataFromApi(string, this);

    } View Presenter public void loadDataFromApi(String query, ArtistCallback artistCallback) { mSpotifyService.searchArtist(query) .subscribeOn(mSpotifyApp.SubscribeScheduler()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(ArtistsSearch -> onSuccess(ArtistsSearch, artistCallback), throwable -> onError(throwable, artistCallback)); } Interactor @Override public boolean onQueryTextSubmit(String query) { artistsPresenter.onSearchArtist(query); return true; } Notify user event Request data Search an Artist
  19. private void onSuccess(ArtistsSearch artistsSearch, ArtistCallback artistCallback) { if (artistsSearch.getArtists() !=

    null) { if (artistsSearch.getArtists().size() > 0) { artistCallback.onResponse(artistsSearch.getArtists()); } else { artistCallback.onArtistNotFound(); } } Delivers entities Interactor @Override public void onResponse(List<Artist> artists) { artistsMvpView.hideLoading(); artistsMvpView.renderArtists(artists); } Presenter View Update UI with entities @Override public void renderArtists(List<Artist> artists) { ArtistsAdapter adapter = (ArtistsAdapter) rv_artist.getAdapter(); adapter.setArtists(artists); adapter.notifyDataSetChanged(); }
  20. None
  21. None
  22. None
  23. Model View ViewModel View ViewModel Model DataBinding and Commands ViewModel

    updates the model Send Notifications Send Notifications
  24. None
  25. • •

  26. dataBinding { enabled = true }

  27. None
  28. None
  29. None
  30. Kata

  31. None
  32. None
  33. • These patterns try to solve the same problems •

    Both patterns are going to improve code quality and testability. • Think about these patterns and use the one you understand better.
  34. None
  35. • Effective Android UI https://www.youtube. com/watch?v=N6yqe88ysNw • Data Binding --

    Write Apps Faster https://www. youtube.com/watch?v=NBbeQMOcnZ0 • MVVM_Hacker_News https://github.com/hitherejoe/MVVM_Hacker_News • My Personal Blog https://erikcaffrey.github.io
  36. Erik Jhordan González Reyes Android Developer +Erik Jhordan Rey Caffrey

    @ErikJhordan_Rey erikcaffrey erikcaffrey.github.io
  37. None