Source:
<code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fui_forgot_password_layout); mHandler = ViewModelProviders.of(this).get(RecoverPasswordHandler.class); mHandler.init(getFlowHolder()); <START> mHandler.getPasswordResetListener().observe(this, new Observer<Task<String>>() { <END> @Override public void onChanged(Task<String> task) { if (task.isSuccessful()) { mEmailInputLayout.setError(null); RecoveryEmailSentDialog.show(task.getResult(), getSupportFragmentManager()); } else if (task.getException() instanceof FirebaseAuthInvalidUserException || task.getException() instanceof FirebaseAuthInvalidCredentialsException) { mEmailInputLayout.setError(getString(R.string.fui_error_email_does_not_exist)); } else { mEmailInputLayout.setError(task.getException().getLocalizedMessage()); } } }); getFlowHolder().getProgressListener().observe(this, new Observer<Boolean>() { @Override public void onChanged(Boolean isDone) { if (isDone) { getDialogHolder().dismissDialog(); } else { getDialogHolder().showLoadingDialog(R.string.fui_progress_dialog_sending); } } }); mEmailInputLayout = findViewById(R.id.email_layout); mEmailEditText = findViewById(R.id.email); mEmailFieldValidator = new EmailFieldValidator(mEmailInputLayout); String email = getIntent().getStringExtra(ExtraConstants.EXTRA_EMAIL); if (email != null) { mEmailEditText.setText(email); } ImeHelper.setImeOnDoneListener(mEmailEditText, this); findViewById(R.id.button_done).setOnClickListener(this); }</code><technical_language>Hmm this a strange me. call a getListener method observe a listener? I want is Observable<PasswordResetState> state include properties boolean success String errorMessage. avoids passing Task lets encapsulate error instanceof logic higher up</technical_language>

Target:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fui_forgot_password_layout); mHandler = ViewModelProviders.of(this).get(RecoverPasswordHandler.class); mHandler.init(getFlowHolder().getArguments()); mHandler.getProgressLiveData().observe(this, new Observer<Resource<String>>() { @Override public void onChanged(Resource<String> resource) { if (resource.getState() == State.LOADING) { getDialogHolder().showLoadingDialog(R.string.fui_progress_dialog_sending); return; } getDialogHolder().dismissDialog(); if (resource.getState() == State.SUCCESS) { mEmailInputLayout.setError(null); showEmailSentDialog(resource.getValue()); } else if (resource.getException() instanceof FirebaseAuthInvalidUserException || resource.getException() instanceof FirebaseAuthInvalidCredentialsException) { mEmailInputLayout.setError(getString(R.string.fui_error_email_does_not_exist)); } else { mEmailInputLayout.setError(resource.getException().getLocalizedMessage()); } } }); mEmailInputLayout = findViewById(R.id.email_layout); mEmailEditText = findViewById(R.id.email); mEmailFieldValidator = new EmailFieldValidator(mEmailInputLayout); String email = getIntent().getStringExtra(ExtraConstants.EXTRA_EMAIL); if (email != null) { mEmailEditText.setText(email); } ImeHelper.setImeOnDoneListener(mEmailEditText, this); findViewById(R.id.button_done).setOnClickListener(this); }