Advertisement
Neyasbit

presenter

Jul 15th, 2019
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. public class HomePresenter {
  2.  
  3.     private HomeView view;
  4.  
  5.     public HomePresenter(HomeView view) {
  6.         this.view = view;
  7.     }
  8.  
  9.     void getData(int offset) {
  10.  
  11.         Call<PokemonData> pokemonDataCall = Utils.getApi().getData(offset, 30);
  12.  
  13.         pokemonDataCall.enqueue(new Callback<PokemonData>() {
  14.             @Override
  15.             public void onResponse(Call<PokemonData> call, Response<PokemonData> response) {
  16.  
  17.                 HomeActivity.setIsLoading(true);
  18.  
  19.                 if (response.isSuccessful() && response.body() != null) {
  20.                     view.setData(response.body().getResults());
  21.                 }
  22.                 else {
  23.                     view.onErrorLoading(response.message());
  24.                 }
  25.             }
  26.  
  27.             @Override
  28.             public void onFailure(Call<PokemonData> call, Throwable t) {
  29.                 HomeActivity.setIsLoading(true);
  30.                 view.onErrorLoading(t.getLocalizedMessage());
  31.             }
  32.         });
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement