Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HomeActivity extends AppCompatActivity implements HomeView{
- @BindView(R.id.recyclerView)
- RecyclerView recyclerView;
- HomePresenter presenter;
- private static int offset;
- private static boolean isLoading;
- public static void setIsLoading(boolean isLoading) {
- HomeActivity.isLoading = isLoading;
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_home);
- ButterKnife.bind(this);
- presenter = new HomePresenter(this);
- presenter.getData(offset);
- offset = 0;
- isLoading = true;
- }
- @Override
- public void setData(List<PokemonData.Pokemon> pokemons) {
- RecyclerViewHomeAdapter homeAdapter = new RecyclerViewHomeAdapter(pokemons, this);
- recyclerView.setAdapter(homeAdapter);
- GridLayoutManager layoutManager = new GridLayoutManager(this, 2, RecyclerView.VERTICAL, false);
- recyclerView.setLayoutManager(layoutManager)
- recyclerView.setOnScrollListener(new RecyclerViewOnScroll() {
- @Override
- protected void loadMore() {
- if (isLoading) {
- isLoading = false;
- offset+=30;
- presenter.getData(offset);
- homeAdapter.insertData(pokemons);
- }
- }
- });
- homeAdapter.notifyDataSetChanged();
- }
- @Override
- public void onErrorLoading(String message) {
- Utils.showDialogMessage(this, "Tittle", message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement