esta guardar e nao esta a entar no perfil
This commit is contained in:
@@ -10,7 +10,7 @@ public class User {
|
||||
public String name;
|
||||
public String email;
|
||||
public String password;
|
||||
public int age;
|
||||
public String age; // Changed to String to prevent deserialization crashes
|
||||
public String utenteNumber;
|
||||
public String profilePictureUri;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class User {
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String name, String email, String password, int age, String utenteNumber) {
|
||||
public User(String name, String email, String password, String age, String utenteNumber) {
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
|
||||
@@ -25,16 +25,23 @@ public class LoginActivity extends AppCompatActivity {
|
||||
// Initialize Firebase Auth
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
|
||||
// Check if user is already logged in
|
||||
// Check if user is already logged in and wants to be remembered
|
||||
SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
|
||||
boolean isLoggedIn = prefs.getBoolean("is_logged_in", false);
|
||||
boolean rememberMe = prefs.getBoolean("remember_me", false);
|
||||
|
||||
if (isLoggedIn && rememberMe) {
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
finish();
|
||||
return;
|
||||
if (mAuth.getCurrentUser() != null) {
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Sign out to prevent ghost sessions if they didn't want to be remembered
|
||||
if (mAuth.getCurrentUser() != null) {
|
||||
mAuth.signOut();
|
||||
}
|
||||
prefs.edit().clear().apply();
|
||||
}
|
||||
|
||||
binding = ActivityLoginBinding.inflate(getLayoutInflater());
|
||||
|
||||
@@ -40,6 +40,11 @@ public class RegisterActivity extends AppCompatActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
if (utenteStr.length() != 9) {
|
||||
Toast.makeText(this, "O Nº de Utente tem de ter 9 dígitos", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
int age = Integer.parseInt(ageStr);
|
||||
|
||||
binding.registerButton.setEnabled(false);
|
||||
|
||||
@@ -37,7 +37,6 @@ public class MedicationViewModel extends AndroidViewModel {
|
||||
|
||||
db.collection("medicamentos")
|
||||
.whereEqualTo("userId", userId)
|
||||
.orderBy("time", Query.Direction.ASCENDING)
|
||||
.addSnapshotListener((value, error) -> {
|
||||
if (error != null) {
|
||||
Log.e("MedicationViewModel", "Listen failed.", error);
|
||||
@@ -48,9 +47,19 @@ public class MedicationViewModel extends AndroidViewModel {
|
||||
if (value != null) {
|
||||
for (QueryDocumentSnapshot doc : value) {
|
||||
Medication med = doc.toObject(Medication.class);
|
||||
med.id = doc.getId(); // Ensure ID is set
|
||||
meds.add(med);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort locally to avoid needing a composite index in Firestore
|
||||
meds.sort((m1, m2) -> {
|
||||
if (m1.time == null && m2.time == null) return 0;
|
||||
if (m1.time == null) return 1;
|
||||
if (m2.time == null) return -1;
|
||||
return m1.time.compareTo(m2.time);
|
||||
});
|
||||
|
||||
allMedications.setValue(meds);
|
||||
|
||||
if (!meds.isEmpty()) {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ProfileFragment extends Fragment {
|
||||
if (currentUser != null && isAdded()) {
|
||||
binding.profileName.setText(currentUser.name);
|
||||
binding.profileEmail.setText(currentUser.email);
|
||||
binding.profileAge.setText(String.valueOf(currentUser.age));
|
||||
binding.profileAge.setText(currentUser.age != null ? currentUser.age : "N/A");
|
||||
binding.profileUtente
|
||||
.setText(currentUser.utenteNumber != null ? currentUser.utenteNumber : "N/A");
|
||||
|
||||
@@ -132,7 +132,7 @@ public class ProfileFragment extends Fragment {
|
||||
View btnCancel = dialogView.findViewById(R.id.button_cancel);
|
||||
|
||||
editName.setText(currentUser.name);
|
||||
editAge.setText(String.valueOf(currentUser.age));
|
||||
editAge.setText(currentUser.age != null ? currentUser.age : "");
|
||||
editUtente.setText(currentUser.utenteNumber);
|
||||
editEmail.setText(currentUser.email);
|
||||
|
||||
@@ -158,11 +158,15 @@ public class ProfileFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
|
||||
int newAge = Integer.parseInt(ageStr);
|
||||
if (newUtente.length() != 9) {
|
||||
Toast.makeText(getContext(), "O Nº de Utente tem de ter 9 dígitos", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean emailChanged = !newEmail.equals(currentUser.email);
|
||||
|
||||
currentUser.name = newName;
|
||||
currentUser.age = newAge;
|
||||
currentUser.age = ageStr;
|
||||
currentUser.utenteNumber = newUtente;
|
||||
|
||||
if (tempProfileUri != null) {
|
||||
|
||||
@@ -59,8 +59,8 @@ public class Sns24Fragment extends Fragment {
|
||||
com.example.cuida.services.Gemini gemini = new com.example.cuida.services.Gemini();
|
||||
String prompt = "Atua como um assistente de triagem médica (em português europeu). " +
|
||||
"Analisa os seguintes sintomas de um paciente e dá uma resposta curta (1 ou 2 parágrafos no máximo) " +
|
||||
"avaliando a urgência e com uma recomendação clara (ir às urgências, ligar ao SNS 24 ou marcar consulta local). "
|
||||
+
|
||||
"avaliando a situação. Se os sintomas indicarem uma situação grave ou emergência médica, a tua resposta DEVE conter a palavra [GRAVE]. " +
|
||||
"Inclui sempre uma recomendação clara (ir às urgências, ligar ao SNS 24 ou marcar consulta local). " +
|
||||
"Sintomas: " + symptoms;
|
||||
|
||||
gemini.fazerPergunta(prompt, new com.example.cuida.services.Gemini.GeminiCallback() {
|
||||
@@ -68,15 +68,17 @@ public class Sns24Fragment extends Fragment {
|
||||
public void onSuccess(String result) {
|
||||
if (getActivity() != null && binding != null) {
|
||||
getActivity().runOnUiThread(() -> {
|
||||
binding.textAiResult.setText(result);
|
||||
// Limpar a marcação da palavra [GRAVE] para não aparecer ao utilizador
|
||||
String displayResult = result.replace("[GRAVE]", "").trim();
|
||||
binding.textAiResult.setText(displayResult);
|
||||
binding.buttonAiTriage.setEnabled(true);
|
||||
|
||||
String resultLower = result.toLowerCase();
|
||||
if (resultLower.contains("urgência") || resultLower.contains("hospital")
|
||||
if (result.contains("[GRAVE]") || resultLower.contains("grave") || resultLower.contains("urgência") || resultLower.contains("hospital")
|
||||
|| resultLower.contains("112")) {
|
||||
binding.buttonFindHospital.setVisibility(View.VISIBLE);
|
||||
binding.buttonFindHospital.setOnClickListener(v -> {
|
||||
Uri gmmIntentUri = Uri.parse("geo:0,0?q=hospital");
|
||||
Uri gmmIntentUri = Uri.parse("geo:0,0?q=hospital+mais+proximo");
|
||||
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
|
||||
mapIntent.setPackage("com.google.android.apps.maps");
|
||||
startActivity(mapIntent);
|
||||
|
||||
Reference in New Issue
Block a user