Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Last active July 3, 2017 10:50
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 GauravChaddha1996/f9f27aa580d9947657d4dac42bb21e3f to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/f9f27aa580d9947657d4dac42bb21e3f to your computer and use it in GitHub Desktop.
public class MyActivity extends AppCompatActivity implements MyViewInterface {
private MyPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
presenter = new MyPresenter(DataManager.getDataManager());
}
@Override
protected void onStart() {
super.onStart();
// instantiates views and sets on click on them.
initView();
}
@Override
protected void onPause() {
// Detach the view as UI isn't going to be visible
presenter.detachView();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
// Attach the view interface as we want UI updated again.
presenter.attachView(this);
}
private void initView() {
// initialize views and set on click and other stuff here
/* the following line isn't syntactically correct but I
just want to give an idea */
submitButton.setOnClickListener(presenter.saveName(name));
}
@Override
public void updateUI(MyState state) {
/* Update the UI using the MyState object*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment