Skip to content

Instantly share code, notes, and snippets.

@andrzejchm
Last active June 29, 2016 12:18
Show Gist options
  • Save andrzejchm/8acd8a4f59e6b5156607299596fa74c2 to your computer and use it in GitHub Desktop.
Save andrzejchm/8acd8a4f59e6b5156607299596fa74c2 to your computer and use it in GitHub Desktop.
public class GoodPresenter extends SimpleDroidMVPPresenter<GoodView,GoodPresentationModel> {
public void onShowUsersButtonClicked() {
getMvpView().showProgress();
repository.getUsers(new Callback() {
public void onSuccess(List<Users> users) {
usersListFetched(users);
}
public void onFailure(Exception e) {
usersListFetchError(e);
}
})
}
private void usersListFetched(List<Users> users) {
PresentationModel model = getPresentationModel();
model.setUsers(users);
if (getMvpView() == null) {
return;
}
if (model.shouldDisplayEmptyState()) {
getMvpView().showEmptyState();
} else {
getMvpView().showUsersList(model.getAllUsers());
}
if(model.hasAnyUserBirthdayToday()) {
getMvpView().showBirthdayAlert(model.getUsersWithBirthday());
}
}
private void usersListFetchError(Exception e) {
getPresentationModel().setUsersListFetchError(e);
if (getMvpView() != null) {
getMvpView().showUsersListFetchError();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment