I am not able to register in APP

0

I'm trying to register using Firebase. It's all correct there in Firebase, but when I click register in APP, nothing happens, it looks like the button is out of function.

Can anyone help me?

package com.towerapps.thetower.soulchat;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
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;
import com.google.firebase.auth.FirebaseUser;

public class RegisterActivity extends AppCompatActivity {

    private FirebaseAuth mAuth;

    private Toolbar mToolbar;
    private ProgressDialog loadingBar;

    private EditText RegisterUserName;
    private EditText RegisterUserEmail;
    private EditText RegisterUserSenha;
    private Button CriarContaButton;
    private FirebaseAuth.AuthStateListener firebaseAuthStateListener;


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

        mAuth = FirebaseAuth.getInstance();
        firebaseAuthStateListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                if (user !=null){
                    Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                    return;
                }
            }
        };

        mToolbar = (Toolbar) findViewById(R.id.register_toolbar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setTitle("Login");
        mToolbar = (Toolbar) findViewById(R.id.login_toolbar);
        getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);

        RegisterUserName = (EditText) findViewById(R.id.register_nome);
        RegisterUserEmail = (EditText) findViewById(R.id.register_email);
        RegisterUserSenha = (EditText) findViewById(R.id.register_senha);
        CriarContaButton = (Button) findViewById(R.id.criar_conta_button);
        loadingBar = new ProgressDialog(this);

        CriarContaButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String nome = RegisterUserName.getText().toString();
                String email = RegisterUserEmail.getText().toString();
                String senha = RegisterUserSenha.getText().toString();

                CriarConta(nome, email, senha);
            }
        });

    }

    private void CriarConta(String nome, String email, String senha) {
        if (TextUtils.isEmpty(nome)){
            Toast.makeText(RegisterActivity.this, "Digite seu nome.",
            Toast.LENGTH_LONG).show();
        }

        if (TextUtils.isEmpty(email)){
            Toast.makeText(RegisterActivity.this, "Digite seu email.",
                    Toast.LENGTH_LONG).show();

            if (TextUtils.isEmpty(senha)){
                Toast.makeText(RegisterActivity.this, "Digite sua senha.",
                        Toast.LENGTH_LONG).show();
            }
            else {
                loadingBar.setTitle("Criar nova conta");
                loadingBar.setMessage("Aguarde, enquanto estamos criando uma conta para você");
                loadingBar.show();

                mAuth.createUserWithEmailAndPassword(email, senha)
                        .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                            @Override
                            public void onComplete(@NonNull Task<AuthResult> task) {
                                if (task.isSuccessful()){
                                    Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
                                    mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                    startActivity(mainIntent);
                                    finish();
                                }
                                else
                                {
                                    Toast.makeText(RegisterActivity.this, "Ocorreu um erro, tente novamente...", Toast.LENGTH_SHORT).show();
                                }

                                loadingBar.dismiss();

                            }
                        });
            }
        }
    }
    @Override
    protected void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(firebaseAuthStateListener);
    }

    @Override
    protected void onStop() {
        super.onStop();
        mAuth.removeAuthStateListener(firebaseAuthStateListener);
    }
}
    
asked by anonymous 26.10.2017 / 22:38

0 answers