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 String age; // Changed to String to prevent deserialization crashes
|
||||
public int age;
|
||||
public String utenteNumber;
|
||||
public String profilePictureUri;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class User {
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String name, String email, String password, String age, String utenteNumber) {
|
||||
public User(String name, String email, String password, int age, String utenteNumber) {
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
|
||||
@@ -20,9 +20,24 @@ public class ForgotPasswordActivity extends AppCompatActivity {
|
||||
if (email.isEmpty()) {
|
||||
Toast.makeText(this, "Por favor insira o seu email.", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
// Mock reset logic
|
||||
Toast.makeText(this, "Email de recuperação enviado para " + email, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
// Real Firebase Password Reset Logic
|
||||
com.google.firebase.auth.FirebaseAuth.getInstance().sendPasswordResetEmail(email)
|
||||
.addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
Toast.makeText(this, "Email de recuperação enviado para " + email, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
} else {
|
||||
String errorMsg = task.getException() != null ? task.getException().getMessage() : "Erro desconhecido";
|
||||
if (errorMsg != null) {
|
||||
if (errorMsg.contains("There is no user record")) {
|
||||
errorMsg = "Não existe conta associada a este email.";
|
||||
} else if (errorMsg.contains("badly formatted")) {
|
||||
errorMsg = "O formato do email é inválido.";
|
||||
}
|
||||
}
|
||||
Toast.makeText(this, "Erro: " + errorMsg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -104,4 +104,4 @@ public class RegisterActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,11 +58,29 @@ public class ProfileFragment extends Fragment {
|
||||
db.collection("utilizadores").document(userId).get()
|
||||
.addOnSuccessListener(documentSnapshot -> {
|
||||
if (documentSnapshot.exists()) {
|
||||
currentUser = documentSnapshot.toObject(User.class);
|
||||
currentUser = new User();
|
||||
currentUser.id = documentSnapshot.getId();
|
||||
currentUser.name = documentSnapshot.getString("name");
|
||||
currentUser.email = documentSnapshot.getString("email");
|
||||
currentUser.utenteNumber = documentSnapshot.getString("utenteNumber");
|
||||
currentUser.profilePictureUri = documentSnapshot.getString("profilePictureUri");
|
||||
|
||||
Object ageObj = documentSnapshot.get("age");
|
||||
if (ageObj instanceof Long) {
|
||||
currentUser.age = ((Long) ageObj).intValue();
|
||||
} else if (ageObj instanceof String) {
|
||||
try {
|
||||
currentUser.age = Integer.parseInt((String) ageObj);
|
||||
} catch (NumberFormatException e) {
|
||||
currentUser.age = 0;
|
||||
}
|
||||
} else {
|
||||
currentUser.age = 0;
|
||||
}
|
||||
if (currentUser != null && isAdded()) {
|
||||
binding.profileName.setText(currentUser.name);
|
||||
binding.profileEmail.setText(currentUser.email);
|
||||
binding.profileAge.setText(currentUser.age != null ? currentUser.age : "N/A");
|
||||
binding.profileAge.setText(String.valueOf(currentUser.age));
|
||||
binding.profileUtente
|
||||
.setText(currentUser.utenteNumber != null ? currentUser.utenteNumber : "N/A");
|
||||
|
||||
@@ -132,7 +150,7 @@ public class ProfileFragment extends Fragment {
|
||||
View btnCancel = dialogView.findViewById(R.id.button_cancel);
|
||||
|
||||
editName.setText(currentUser.name);
|
||||
editAge.setText(currentUser.age != null ? currentUser.age : "");
|
||||
editAge.setText(String.valueOf(currentUser.age));
|
||||
editUtente.setText(currentUser.utenteNumber);
|
||||
editEmail.setText(currentUser.email);
|
||||
|
||||
@@ -163,10 +181,15 @@ public class ProfileFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
|
||||
int newAge = 0;
|
||||
try {
|
||||
newAge = Integer.parseInt(ageStr);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
|
||||
boolean emailChanged = !newEmail.equals(currentUser.email);
|
||||
|
||||
currentUser.name = newName;
|
||||
currentUser.age = ageStr;
|
||||
currentUser.age = newAge;
|
||||
currentUser.utenteNumber = newUtente;
|
||||
|
||||
if (tempProfileUri != null) {
|
||||
|
||||
@@ -74,6 +74,34 @@ public class ScheduleAppointmentFragment extends Fragment {
|
||||
|
||||
// Prevent past dates
|
||||
datePicker.setMinDate(System.currentTimeMillis() - 1000);
|
||||
|
||||
// Hide the year component
|
||||
int yearSpinnerId = android.content.res.Resources.getSystem().getIdentifier("year", "id", "android");
|
||||
if (yearSpinnerId != 0) {
|
||||
View yearSpinner = datePicker.findViewById(yearSpinnerId);
|
||||
if (yearSpinner != null) {
|
||||
yearSpinner.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
// Put month on left, day on right
|
||||
int daySpinnerId = android.content.res.Resources.getSystem().getIdentifier("day", "id", "android");
|
||||
int monthSpinnerId = android.content.res.Resources.getSystem().getIdentifier("month", "id", "android");
|
||||
if (daySpinnerId != 0 && monthSpinnerId != 0) {
|
||||
View daySpinner = datePicker.findViewById(daySpinnerId);
|
||||
View monthSpinner = datePicker.findViewById(monthSpinnerId);
|
||||
if (daySpinner != null && monthSpinner != null) {
|
||||
ViewGroup parent = (ViewGroup) daySpinner.getParent();
|
||||
if (parent != null && parent.equals(monthSpinner.getParent())) {
|
||||
int dIndex = parent.indexOfChild(daySpinner);
|
||||
int mIndex = parent.indexOfChild(monthSpinner);
|
||||
if (mIndex > dIndex) {
|
||||
parent.removeView(monthSpinner);
|
||||
parent.addView(monthSpinner, dIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupRecyclerView() {
|
||||
|
||||
Reference in New Issue
Block a user