SignUpActivity Firebase Auth

Advertisements
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class SignUpActivity extends AppCompatActivity {

  private EditText mEtEmail, mEtPassword, mEtConfirmPassword;
  private TextView mTvSignUp;
  private RelativeLayout mRlRoot, mRlFading;
  private ProgressBar mProgressBar;

  private static final String TAG = "SignUpActivity";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up);

    mEtEmail = findViewById(R.id.etEmail);
    mEtPassword = findViewById(R.id.etPass);
    mEtConfirmPassword = findViewById(R.id.etPassConfirm);

    mTvSignUp = findViewById(R.id.txtBtnSignUp);

    mRlFading = findViewById(R.id.rlFadingLayout);
    mRlRoot = findViewById(R.id.rlRoot);

    mProgressBar  = findViewById(R.id.progressBar);

    mTvSignUp.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View view) {
        String pass = mEtPassword.getText().toString();
        String confirmPass = mEtConfirmPassword.getText().toString();
        String email = mEtEmail.getText().toString();



        if (!pass.equals(confirmPass)) {
          Snackbar.make(mRlRoot, "Password Doesn't match", Snackbar.LENGTH_LONG).show();
        } else {
          mProgressBar.setVisibility(View.VISIBLE);
          mRlFading.setVisibility(View.VISIBLE);
          FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
          firebaseAuth.createUserWithEmailAndPassword(email, pass).addOnCompleteListener(
              new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {

                  if (task.isSuccessful()) {
                    Toast.makeText(SignUpActivity.this, "SignUp Complete", Toast.LENGTH_SHORT)
                        .show();
                    startActivity(new Intent(SignUpActivity.this, MainActivity.class));
                    finish();
                  } else {
                    Snackbar.make(mRlRoot, task.getException().getMessage(), Snackbar.LENGTH_LONG)
                        .show();
                  }

                }
              });
        }


      }
    });


  }
}