corrigir os novos erros amnhã e adicionar qual tipo de sexo a pessoa é no register
This commit is contained in:
@@ -3,9 +3,10 @@ package com.example.pap;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -16,7 +17,8 @@ import retrofit2.Response;
|
||||
|
||||
public class RegisterActivity extends AppCompatActivity {
|
||||
|
||||
private EditText etRegNome, etRegEmail, etRegPassword, etRegAltura, etRegPeso;
|
||||
private EditText etRegNome, etRegEmail, etRegPassword, etRegAltura, etRegPeso, etRegIdade;
|
||||
private RadioGroup radioGroupSexo;
|
||||
private Button btnRegister;
|
||||
private TextView tvGoToLogin;
|
||||
|
||||
@@ -29,8 +31,10 @@ public class RegisterActivity extends AppCompatActivity {
|
||||
etRegNome = findViewById(R.id.etRegNome);
|
||||
etRegEmail = findViewById(R.id.etRegEmail);
|
||||
etRegPassword = findViewById(R.id.etRegPassword);
|
||||
etRegIdade = findViewById(R.id.etRegIdade);
|
||||
etRegAltura = findViewById(R.id.etRegAltura);
|
||||
etRegPeso = findViewById(R.id.etRegPeso);
|
||||
radioGroupSexo = findViewById(R.id.radioGroupSexo);
|
||||
btnRegister = findViewById(R.id.btnRegister);
|
||||
tvGoToLogin = findViewById(R.id.tvGoToLogin);
|
||||
|
||||
@@ -42,20 +46,37 @@ public class RegisterActivity extends AppCompatActivity {
|
||||
String nome = etRegNome.getText().toString().trim();
|
||||
String email = etRegEmail.getText().toString().trim();
|
||||
String password = etRegPassword.getText().toString().trim();
|
||||
String idadeStr = etRegIdade.getText().toString().trim();
|
||||
String alturaStr = etRegAltura.getText().toString().trim();
|
||||
String pesoStr = etRegPeso.getText().toString().trim();
|
||||
|
||||
// 1. Verificar se não há campos vazios
|
||||
if (nome.isEmpty() || email.isEmpty() || password.isEmpty() || alturaStr.isEmpty() || pesoStr.isEmpty()) {
|
||||
if (nome.isEmpty() || email.isEmpty() || password.isEmpty() || idadeStr.isEmpty() || alturaStr.isEmpty() || pesoStr.isEmpty()) {
|
||||
Toast.makeText(this, "Por favor, preenche todos os campos!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. GUARDAR NOME, ALTURA E PESO NA MEMÓRIA (SharedPreferences)
|
||||
// 1.1 Verificar se o utilizador escolheu o sexo
|
||||
int selectedSexoId = radioGroupSexo.getCheckedRadioButtonId();
|
||||
if (selectedSexoId == -1) {
|
||||
Toast.makeText(this, "Por favor, escolhe o teu sexo!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String sexoSelecionado = "";
|
||||
if (selectedSexoId == R.id.radioMasculino) {
|
||||
sexoSelecionado = "Masculino";
|
||||
} else if (selectedSexoId == R.id.radioFeminino) {
|
||||
sexoSelecionado = "Feminino";
|
||||
}
|
||||
|
||||
// 2. GUARDAR TODOS OS DADOS NA MEMÓRIA (SharedPreferences)
|
||||
SharedPreferences prefs = getSharedPreferences("MeusDadosApp", MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString("nome", nome);
|
||||
editor.putString("email", email);
|
||||
editor.putString("sexo", sexoSelecionado);
|
||||
editor.putInt("idade", Integer.parseInt(idadeStr));
|
||||
editor.putFloat("altura", Float.parseFloat(alturaStr));
|
||||
editor.putFloat("peso", Float.parseFloat(pesoStr));
|
||||
editor.apply();
|
||||
@@ -73,7 +94,7 @@ public class RegisterActivity extends AppCompatActivity {
|
||||
if (response.isSuccessful()) {
|
||||
Toast.makeText(RegisterActivity.this, "Conta criada! Verifica o teu email.", Toast.LENGTH_LONG).show();
|
||||
|
||||
// NOVO FLUXO: Mandar para o ecrã de espera com os dados passados em segurança!
|
||||
// Mandar para o ecrã de espera
|
||||
Intent intent = new Intent(RegisterActivity.this, VerificacaoActivity.class);
|
||||
intent.putExtra("email_registo", email);
|
||||
intent.putExtra("password_registo", password);
|
||||
@@ -87,7 +108,6 @@ public class RegisterActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SupabaseResponse> call, Throwable t) {
|
||||
// Sem internet ou falha de ligação
|
||||
Toast.makeText(RegisterActivity.this, "Falha na ligação! Verifica a tua internet.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user