Skip to content

Instantly share code, notes, and snippets.

@BartoszJarocki
Last active May 13, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BartoszJarocki/822ccd09e836d11d4e1f99c8cf7b9150 to your computer and use it in GitHub Desktop.
Save BartoszJarocki/822ccd09e836d11d4e1f99c8cf7b9150 to your computer and use it in GitHub Desktop.
public class ContributorsPresenter extends MvpBasePresenter<ContributorsView> {
private AppRepository appRepository;
private Subscription subscription;
public ContributorsPresenter(final AppRepository appRepository) {
this.appRepository = appRepository;
}
public void loadContributors(String owner, String repo, boolean pullToRefresh) {
if (isViewAttached()) {
getView().showProgress(pullToRefresh);
}
subscription =
appRepository.contributors(owner, repo).subscribe(new Subscriber<List<Contributor>>() {
@Override
public void onCompleted() {
Timber.d("Finished loading contributors.");
}
@Override
public void onError(final Throwable e) {
if (isViewAttached()) {
getView().showError(e.toString());
}
}
@Override
public void onNext(final List<Contributor> contributors) {
if (!isViewAttached()) {
return;
}
if (contributors != null && !contributors.isEmpty()) {
getView().showContributors(contributors);
} else {
getView().showEmpty();
}
}
});
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment