Created
May 30, 2017 08:33
-
-
Save EfeBudak/6a8b3ba572779689d2324f04172391db to your computer and use it in GitHub Desktop.
Android Pagination with MVP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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