Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Medium - Android/Java Interfaces like a Boss! - Contracts implementations (View)
public class MainActivity extends AppCompatActivity implements ViewContract {
private AccountManagerPresenter presenter;
private Button updateAccountButton;
private Button removeAccountButton;
private EditText nameInput;
private EditText emailInput;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupViews();
setupPresenter();
setupButtonsClick();
}
private void setupViews() {
// Inicialização dos Buttons e EditTexts através
// do findViewById...
//...
}
private void setupPresenter() {
presenter = new AccountManagerPresenterImpl(this);
}
private void setupButtonsClick() {
updateAccountButton.setOnClickListener(v -> onUpdateAccountButtonClick());
removeAccountButton.setOnClickListener(v -> presenter.onRemoveAccount());
}
private void onUpdateAccountButtonClick() {
presenter.onUpdateAccount(getTypedName(), getTypedEmail());
}
private String getTypedName() {
return nameInput.getText().toString();
}
private String getTypedEmail() {
return emailInput.getText().toString();
}
@Override
public void onShowLoading() {
// Executado quando o presenter precisar
// exibir o diálogo de progresso
}
@Override
public void onHideLoading() {
// Executado quando o presenter precisar
// esconder o diálogo de progresso
}
@Override
public void onShowError(String error) {
// Executado quando o presenter notificar
// sobre qualquer erro ocorrido
}
@Override
public void onAccountUpdate() {
// Executado quando o presenter obtiver sucesso
// em atualizar a conta
}
@Override
public void onAccountRemoved() {
// Executado quando o presenter obtiver sucesso
// em remover a conta
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment