corrigir os novos erros amnhã e adicionar qual tipo de sexo a pessoa é no register
This commit is contained in:
@@ -11,8 +11,9 @@ import java.util.Locale;
|
||||
|
||||
public class EstatisticasActivity extends AppCompatActivity {
|
||||
|
||||
private TextView tvValorIMC, tvStatusIMC;
|
||||
private TextView tvValorIMC, tvStatusIMC, tvCaloriasMeta;
|
||||
private TextView tvProtGramas, tvHidrGramas, tvGordGramas, tvComida1;
|
||||
private TextView tvAguaStats;
|
||||
private ProgressBar progressProt, progressHidr, progressGord;
|
||||
|
||||
@Override
|
||||
@@ -23,12 +24,15 @@ public class EstatisticasActivity extends AppCompatActivity {
|
||||
// Ligar o layout (XML) às variáveis do Java
|
||||
tvValorIMC = findViewById(R.id.tvValorIMC);
|
||||
tvStatusIMC = findViewById(R.id.tvStatusIMC);
|
||||
tvCaloriasMeta = findViewById(R.id.tvCaloriasMeta);
|
||||
|
||||
tvProtGramas = findViewById(R.id.tvProtGramas);
|
||||
tvHidrGramas = findViewById(R.id.tvHidrGramas);
|
||||
tvGordGramas = findViewById(R.id.tvGordGramas);
|
||||
tvComida1 = findViewById(R.id.tvComida1);
|
||||
|
||||
tvAguaStats = findViewById(R.id.tvAguaStats);
|
||||
|
||||
progressProt = findViewById(R.id.progressProt);
|
||||
progressHidr = findViewById(R.id.progressHidr);
|
||||
progressGord = findViewById(R.id.progressGord);
|
||||
@@ -36,9 +40,11 @@ public class EstatisticasActivity extends AppCompatActivity {
|
||||
// Botão voltar
|
||||
findViewById(R.id.btnVoltarStats).setOnClickListener(v -> finish());
|
||||
|
||||
// Chamar as duas funções que preenchem os dados
|
||||
// Chamar as funções que preenchem os dados
|
||||
calcularIMC();
|
||||
calcularTMB();
|
||||
carregarMacrosDaIA();
|
||||
carregarAgua();
|
||||
}
|
||||
|
||||
private void calcularIMC() {
|
||||
@@ -69,8 +75,36 @@ public class EstatisticasActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void calcularTMB() {
|
||||
SharedPreferences prefs = getSharedPreferences("MeusDadosApp", MODE_PRIVATE);
|
||||
float peso = prefs.getFloat("peso", 0);
|
||||
float alturaMetros = prefs.getFloat("altura", 0);
|
||||
String sexo = prefs.getString("sexo", "");
|
||||
|
||||
// Puxa a idade real. Se der erro ou não existir, assume 20.
|
||||
int idade = prefs.getInt("idade", 20);
|
||||
|
||||
if (peso > 0 && alturaMetros > 0 && !sexo.isEmpty()) {
|
||||
float alturaCm = alturaMetros * 100; // Passar para centímetros
|
||||
double tmb;
|
||||
|
||||
// Fórmula de Harris-Benedict
|
||||
if (sexo.equals("Masculino")) {
|
||||
tmb = (10 * peso) + (6.25 * alturaCm) - (5 * idade) + 5;
|
||||
} else {
|
||||
tmb = (10 * peso) + (6.25 * alturaCm) - (5 * idade) - 161;
|
||||
}
|
||||
|
||||
// Fator de atividade leve para dar uma meta real (1.2)
|
||||
double caloriasTotais = tmb * 1.2;
|
||||
|
||||
tvCaloriasMeta.setText(String.valueOf((int) caloriasTotais));
|
||||
} else {
|
||||
tvCaloriasMeta.setText("--");
|
||||
}
|
||||
}
|
||||
|
||||
private void carregarMacrosDaIA() {
|
||||
// Abre a memória onde a FotoActivity guardou os dados
|
||||
SharedPreferences prefs = getSharedPreferences("DadosSaude", MODE_PRIVATE);
|
||||
|
||||
int prot = prefs.getInt("prot_hoje", 0);
|
||||
@@ -78,17 +112,23 @@ public class EstatisticasActivity extends AppCompatActivity {
|
||||
int gord = prefs.getInt("gord_hoje", 0);
|
||||
String ultimaComida = prefs.getString("ultimo_prato", "Ainda não leste nada hoje.");
|
||||
|
||||
// Atualizar os Textos (ex: "Proteína: 25g")
|
||||
tvProtGramas.setText("Proteína: " + prot + "g");
|
||||
tvHidrGramas.setText("Hidratos: " + hidr + "g");
|
||||
tvGordGramas.setText("Gordura: " + gord + "g");
|
||||
|
||||
// Atualizar as Barras (Vai enchendo de 0 até ao limite máximo que definiste no XML)
|
||||
progressProt.setProgress(prot);
|
||||
progressHidr.setProgress(hidr);
|
||||
progressGord.setProgress(gord);
|
||||
|
||||
// Atualiza a Última Comida
|
||||
tvComida1.setText("1. " + ultimaComida);
|
||||
tvComida1.setText(ultimaComida);
|
||||
}
|
||||
|
||||
private void carregarAgua() {
|
||||
SharedPreferences prefs = getSharedPreferences("DadosGamificacao", MODE_PRIVATE);
|
||||
int coposBebidos = prefs.getInt("agua_hoje", 0);
|
||||
|
||||
float litrosTotais = coposBebidos * 0.25f;
|
||||
|
||||
tvAguaStats.setText(String.format(Locale.getDefault(), "💧 %.2f L", litrosTotais));
|
||||
}
|
||||
}
|
||||
@@ -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