Last active
February 9, 2017 00:52
-
-
Save yemyatthu1990/cecacbe442c773137c3aab4abfb32801 to your computer and use it in GitHub Desktop.
This file contains 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
public class TownshipListPresenter implements Presenter{ | |
private TownshipListView townshipListView; | |
private final GetTownshipList getTownshipList; | |
private final TownshipModelMapper townshipModelMapper; | |
public TownshipListPresenter(GetTownshipList getTownshipList,TownshipModelMapper townshipModelMapper){ | |
this.getTownshipList = getTownshipList; | |
this.townshipModelMapper = townshipModelMapper; | |
} | |
public void setTownshipListView(TownshipListView townshipListView){ | |
this.townshipListView = townshipListView; | |
} | |
@Override | |
public void resume() { | |
} | |
@Override | |
public void pause() { | |
} | |
@Override | |
public void destroy() { | |
this.getTownshipList.dispose(); | |
this.townshipListView = null; | |
} | |
public void initialize(){ | |
this.loadTownshipList(); | |
} | |
private void loadTownshipList() { | |
this.showViewLoading(); | |
this.getTownshipList(); | |
} | |
private void showViewLoading() { | |
this.townshipListView.showLoading(); | |
} | |
private void hideViewLoading() { | |
this.townshipListView.hideLoading(); | |
} | |
private void showErrorMessage(String errorMessage) { | |
this.townshipListView.showError(errorMessage); | |
} | |
private void showTownshipListInView(List<Township> townships) { | |
final List<TownshipModel> townshipModelList = | |
this.townshipModelMapper.transformList(townships); | |
this.townshipListView.renderTownshipList(townshipModelList); | |
} | |
private void getTownshipList() { | |
this.getTownshipList.execute(new TownshipListObserver(), null); | |
} | |
private final class TownshipListObserver extends DefaultObserver<List<Township>> { | |
@Override public void onComplete() { | |
TownshipListPresenter.this.hideViewLoading(); | |
} | |
@Override public void onError(Throwable e) { | |
e.printStackTrace(); | |
TownshipListPresenter.this.hideViewLoading(); | |
TownshipListPresenter.this.showErrorMessage(e.getLocalizedMessage()); | |
} | |
@Override public void onNext(List<Township> townships) { | |
TownshipListPresenter.this.showTownshipListInView(townships); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment