Login feito, Criar Conta feito e começo da recuperação da password
parent
8fb4ceef95
commit
85a64eb15f
|
|
@ -13,6 +13,9 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.LifeGrid">
|
||||
<activity
|
||||
android:name=".TelaInicialActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".RecupearPasswordActivity"
|
||||
android:exported="false" />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,14 @@
|
|||
package com.example.lifegrid;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Patterns;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
|
@ -8,8 +16,21 @@ import androidx.core.graphics.Insets;
|
|||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.auth.FirebaseUser;
|
||||
|
||||
public class CriarContaActivity extends AppCompatActivity {
|
||||
|
||||
private EditText nomeEditText;
|
||||
private EditText emailEditText2;
|
||||
private EditText passwordEditText3;
|
||||
private EditText passwordEditText2;
|
||||
private Button loginButton2;
|
||||
private Button googleButton2;
|
||||
private ProgressBar loadingProgressBar;
|
||||
private FirebaseAuth firebaseAuth;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -20,5 +41,135 @@ public class CriarContaActivity extends AppCompatActivity {
|
|||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
nomeEditText = findViewById(R.id.emailEditText3);
|
||||
emailEditText2 = findViewById(R.id.emailEditText2);
|
||||
passwordEditText3 = findViewById(R.id.passwordEditText3);
|
||||
passwordEditText2 = findViewById(R.id.passwordEditText2);
|
||||
loginButton2 = findViewById(R.id.loginButton2);
|
||||
googleButton2 = findViewById(R.id.googleButton2);
|
||||
loadingProgressBar = findViewById(R.id.loadingProgressBar);
|
||||
|
||||
FirebaseApp.initializeApp(this);
|
||||
firebaseAuth = FirebaseAuth.getInstance();
|
||||
|
||||
loginButton2.setOnClickListener(v -> criarConta());
|
||||
googleButton2.setOnClickListener(v ->
|
||||
Toast.makeText(this, "Login com Google disponível em breve.", Toast.LENGTH_SHORT).show()
|
||||
);
|
||||
}
|
||||
|
||||
private void criarConta() {
|
||||
String nome = nomeEditText.getText().toString().trim();
|
||||
String email = emailEditText2.getText().toString().trim();
|
||||
String password = passwordEditText3.getText().toString();
|
||||
String confirmarPassword = passwordEditText2.getText().toString();
|
||||
|
||||
if (!validarDados(nome, email, password, confirmarPassword)) {
|
||||
return;
|
||||
}
|
||||
|
||||
toggleLoading(true);
|
||||
|
||||
firebaseAuth.createUserWithEmailAndPassword(email, password)
|
||||
.addOnCompleteListener(this, task -> {
|
||||
toggleLoading(false);
|
||||
if (task.isSuccessful()) {
|
||||
FirebaseUser user = firebaseAuth.getCurrentUser();
|
||||
if (user != null) {
|
||||
// Conta criada com sucesso - redirecionar para TelaInicialActivity
|
||||
Toast.makeText(this,
|
||||
"Conta criada com sucesso! Bem-vindo, " + nome,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
// Redirecionar para TelaInicialActivity apenas após sucesso
|
||||
Intent intent = new Intent(CriarContaActivity.this, TelaInicialActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
finish(); // Fechar esta atividade
|
||||
}
|
||||
} else {
|
||||
// Erro ao criar conta - mostrar mensagem de erro
|
||||
String errorMessage = "Erro ao criar conta.";
|
||||
if (task.getException() != null) {
|
||||
errorMessage = task.getException().getMessage();
|
||||
// Traduzir alguns erros comuns para português
|
||||
if (errorMessage.contains("email address is already in use")) {
|
||||
errorMessage = "Este email já está em uso. Por favor, use outro email.";
|
||||
} else if (errorMessage.contains("network")) {
|
||||
errorMessage = "Erro de conexão. Verifique sua internet.";
|
||||
} else if (errorMessage.contains("weak password")) {
|
||||
errorMessage = "Palavra-passe muito fraca. Use uma palavra-passe mais forte.";
|
||||
}
|
||||
}
|
||||
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean validarDados(String nome, String email, String password, String confirmarPassword) {
|
||||
// Validar nome
|
||||
if (TextUtils.isEmpty(nome)) {
|
||||
nomeEditText.setError("Nome obrigatório.");
|
||||
nomeEditText.requestFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nome.length() < 2) {
|
||||
nomeEditText.setError("Nome deve ter pelo menos 2 caracteres.");
|
||||
nomeEditText.requestFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validar email
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
emailEditText2.setError("Email obrigatório.");
|
||||
emailEditText2.requestFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
|
||||
emailEditText2.setError("Formato de email inválido.");
|
||||
emailEditText2.requestFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validar password
|
||||
if (TextUtils.isEmpty(password)) {
|
||||
passwordEditText3.setError("Palavra-passe obrigatória.");
|
||||
passwordEditText3.requestFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (password.length() < 6) {
|
||||
passwordEditText3.setError("Palavra-passe deve ter pelo menos 6 caracteres.");
|
||||
passwordEditText3.requestFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validar confirmação de password
|
||||
if (TextUtils.isEmpty(confirmarPassword)) {
|
||||
passwordEditText2.setError("Por favor, confirme a palavra-passe.");
|
||||
passwordEditText2.requestFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!password.equals(confirmarPassword)) {
|
||||
passwordEditText2.setError("As palavras-passe não coincidem.");
|
||||
passwordEditText2.requestFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void toggleLoading(boolean show) {
|
||||
loadingProgressBar.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
loginButton2.setEnabled(!show);
|
||||
googleButton2.setEnabled(!show);
|
||||
nomeEditText.setEnabled(!show);
|
||||
emailEditText2.setEnabled(!show);
|
||||
passwordEditText3.setEnabled(!show);
|
||||
passwordEditText2.setEnabled(!show);
|
||||
}
|
||||
}
|
||||
|
|
@ -101,7 +101,13 @@ public class LoginActivity extends AppCompatActivity {
|
|||
String welcome = user != null && !TextUtils.isEmpty(user.getEmail())
|
||||
? "Bem-vindo, " + user.getEmail()
|
||||
: "Login realizado com sucesso!";
|
||||
Toast.makeText(this, welcome, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(this, welcome, Toast.LENGTH_SHORT).show();
|
||||
|
||||
// Redirecionar para TelaInicialActivity após login bem-sucedido
|
||||
Intent intent = new Intent(LoginActivity.this, TelaInicialActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
finish(); // Fechar LoginActivity para não poder voltar com back button
|
||||
} else {
|
||||
Toast.makeText(this,
|
||||
task.getException() != null ? task.getException().getMessage() : "Falha no login",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.example.lifegrid;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
public class TelaInicialActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_tela_inicial);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
|
|
@ -3,10 +3,22 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:background="#FFFFFF"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".CriarContaActivity">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/logoImageView"
|
||||
android:layout_width="213dp"
|
||||
android:layout_height="97dp"
|
||||
android:layout_marginTop="76dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.073"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/logo" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView7"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
@ -16,7 +28,7 @@
|
|||
android:textColor="#8A8484"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.326"
|
||||
app:layout_constraintHorizontal_bias="0.251"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView6" />
|
||||
|
||||
|
|
@ -24,14 +36,14 @@
|
|||
android:id="@+id/textView6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="160dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="Criar conta"
|
||||
android:textSize="25sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.166"
|
||||
app:layout_constraintHorizontal_bias="0.128"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/logoImageView" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/passwordEditText2"
|
||||
|
|
@ -83,7 +95,7 @@
|
|||
android:background="@drawable/button_background"
|
||||
android:ems="10"
|
||||
android:hint="O seu nome"
|
||||
android:inputType="textEmailAddress"
|
||||
android:inputType="textPersonName"
|
||||
android:textSize="15dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.52"
|
||||
|
|
@ -175,4 +187,15 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/passwordEditText3" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/loadingProgressBar"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/googleButton2" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -13,14 +13,14 @@
|
|||
android:id="@+id/textView5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="192dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="Bem-vindo/a de volta"
|
||||
android:textSize="25sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.113"
|
||||
app:layout_constraintHorizontal_bias="0.154"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/logoImageView" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
|
|
@ -164,4 +164,15 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/logoImageView"
|
||||
android:layout_width="194dp"
|
||||
android:layout_height="81dp"
|
||||
android:layout_marginTop="92dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/logo" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -7,4 +7,76 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".RecupearPasswordActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/loginButton3"
|
||||
android:layout_width="315dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:backgroundTint="#050505"
|
||||
android:text="Entrar ->"
|
||||
app:cornerRadius="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/emailEditText4" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/emailTextView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
android:text="Email"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.104"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView9" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/emailEditText4"
|
||||
android:layout_width="338dp"
|
||||
android:layout_height="49dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="@drawable/button_background"
|
||||
android:ems="10"
|
||||
android:hint="seu@email.com"
|
||||
android:inputType="textEmailAddress"
|
||||
android:textSize="15dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.493"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/emailTextView2" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/logoImageView2"
|
||||
android:layout_width="283dp"
|
||||
android:layout_height="156dp"
|
||||
android:layout_marginTop="160dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/logo" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView8"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Recuperar password"
|
||||
android:textSize="26dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.23"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/logoImageView2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView9"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Insira o seu email para recuperar a password"
|
||||
android:textSize="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.425"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView8" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".TelaInicialActivity">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Reference in New Issue