Created
June 25, 2017 16:35
-
-
Save GauravChaddha1996/4466d6e79c973fd6466088e6f81af9e1 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
class MyPresenter { | |
private MyViewInterface viewInterface; | |
private DataManager dataManager; | |
private MyState state; | |
MyPresenter(DataManager dataManager) { | |
this.dataManager = dataManager; | |
/* Initiates state with a default value for the initial UI | |
of this view */ | |
state = new MyState("This is the template data"); | |
} | |
/** | |
* Called when the UI became visible in onResume, thus we | |
save the interface object and update the UI with the cached | |
state */ | |
void attachView(MyViewInterface viewInterface) { | |
this.viewInterface = viewInterface; | |
viewInterface.updateUI(state); | |
} | |
/** | |
* Called when the UI became invisible, thus we set the | |
interface object to null as we can't dispatch more UI | |
updates but we keep our state object up to date with | |
the model changes and will update the UI when it attaches | |
again. */ | |
void detachView() { | |
this.viewInterface = null; | |
} | |
/* Button click UI event from submitButton in view to save | |
data in the model which we do using dataManager */ | |
void saveName(String name) { | |
dataManager.saveName(name); | |
state.setNameSaved(name); | |
viewInterface.updateUI(state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment