Advertisement
Neyasbit

Activity

Jul 15th, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. public class HomeActivity extends AppCompatActivity implements HomeView{
  2.  
  3.  
  4.     @BindView(R.id.recyclerView)
  5.     RecyclerView recyclerView;
  6.  
  7.     HomePresenter presenter;
  8.  
  9.     private static int offset;
  10.  
  11.     private static boolean isLoading;
  12.  
  13.     public static void setIsLoading(boolean isLoading) {
  14.         HomeActivity.isLoading = isLoading;
  15.     }
  16.  
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_home);
  21.         ButterKnife.bind(this);
  22.  
  23.         presenter = new HomePresenter(this);
  24.         presenter.getData(offset);
  25.         offset = 0;
  26.         isLoading = true;
  27.     }
  28.  
  29.  
  30.     @Override
  31.     public void setData(List<PokemonData.Pokemon> pokemons) {
  32.         RecyclerViewHomeAdapter homeAdapter = new RecyclerViewHomeAdapter(pokemons, this);
  33.         recyclerView.setAdapter(homeAdapter);
  34.         GridLayoutManager layoutManager = new GridLayoutManager(this, 2, RecyclerView.VERTICAL, false);
  35.         recyclerView.setLayoutManager(layoutManager)
  36.  
  37.         recyclerView.setOnScrollListener(new RecyclerViewOnScroll() {
  38.             @Override
  39.             protected void loadMore() {
  40.  
  41.                 if (isLoading) {
  42.                     isLoading = false;
  43.                     offset+=30;
  44.                     presenter.getData(offset);
  45.                     homeAdapter.insertData(pokemons);
  46.                 }
  47.             }
  48.         });
  49.         homeAdapter.notifyDataSetChanged();
  50.  
  51.     }
  52.  
  53.     @Override
  54.     public void onErrorLoading(String message) {
  55.         Utils.showDialogMessage(this, "Tittle", message);
  56.     }
  57.    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement