Skip to content

Instantly share code, notes, and snippets.

@EfeBudak
Created May 30, 2017 08:33
Show Gist options
  • Save EfeBudak/6a8b3ba572779689d2324f04172391db to your computer and use it in GitHub Desktop.
Save EfeBudak/6a8b3ba572779689d2324f04172391db to your computer and use it in GitHub Desktop.
Android Pagination with MVP
private void getPage() {
mCompositeDisposable.add(mRepository.getPage(mCurrentPage)
.observeOn(mSchedulerProvider.ui())
.subscribeOn(mSchedulerProvider.io())
.subscribeWith(new DisposableSingleObserver<Products>(){
@Override
public void onSuccess( @io.reactivex.annotations.NonNull Products products) {
mView.setRefreshing(false);
mView.refreshPageItems(products.getProducts());
if (products.getNumberPages() <= products.getCurrentPage()) {
mView.stopPagination();
}
mCurrentPage = products.getCurrentPage();
}
@Override
public void onError(@io.reactivex.annotations.NonNull Throwable e) {
mView.setRefreshing(false);
mView.showError();
if (mCurrentPage > 0) {
mCurrentPage--;
}
}
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment