Example
public class LoginActivity extends BaseAppCompatActivity {
@BindView(R.id.tIETLoginEmail)
EditText mEditEmail;
@BindView(R.id.tIETLoginPassword)
EditText mEditPassword;
@Override
protected void onResume() {
super.onResume();
FirebaseUser firebaseUser = mFirebaseAuth.getCurrentUser();
if (firebaseUser != null)
startActivity(new Intent(this, HomeActivity.class));
}
@Override
protected int getLayoutResourceId() {
return R.layout.activity_login;
}
@OnClick(R.id.btnLoginLogin)
void onSignInClick() {
FormValidationUtils.clearErrors(mEditEmail, mEditPassword);
if (FormValidationUtils.isBlank(mEditEmail)) {
FormValidationUtils.setError(null, mEditEmail, "Please enter email");
return;
}
if (!FormValidationUtils.isEmailValid(mEditEmail)) {
FormValidationUtils.setError(null, mEditEmail, "Please enter valid email");
return;
}
if (TextUtils.isEmpty(mEditPassword.getText())) {
FormValidationUtils.setError(null, mEditPassword, "Please enter password");
return;
}
signInWithEmailAndPassword(mEditEmail.getText().toString(), mEditPassword.getText().toString());
}
private void signInWithEmailAndPassword(String email, String password) {
DialogUtils.showProgressDialog(this, "", getString(R.string.sign_in), false);
mFirebaseAuth
.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
DialogUtils.dismissProgressDialog();
if (task.isSuccessful()) {
Toast.makeText(LoginActivity.this, "Login Successful", Toast.LENGTH_SHORT).show();
startActivity(new Intent(LoginActivity.this, HomeActivity.class));
finish();
} else {
Toast.makeText(LoginActivity.this, task.getException().getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
}
@OnClick(R.id.btnLoginSignUp)
void onSignUpClick() {
startActivity(new Intent(this, SignUpActivity.class));
}
@OnClick(R.id.btnLoginForgotPassword)
void forgotPassword() {
startActivity(new Intent(this, ForgotPasswordActivity.class));
}
}