ja acabei a app acho?
This commit is contained in:
@@ -38,8 +38,6 @@ public class AppointmentsViewModel extends AndroidViewModel {
|
||||
// 1. Fetch Future Appointments
|
||||
db.collection("users").document(userId).collection("appointments")
|
||||
.whereEqualTo("isPast", false)
|
||||
.orderBy("date", Query.Direction.ASCENDING)
|
||||
.orderBy("time", Query.Direction.ASCENDING)
|
||||
.addSnapshotListener((value, error) -> {
|
||||
if (error != null) {
|
||||
Log.e("AppointmentsVM", "Listen failed for future.", error);
|
||||
@@ -52,14 +50,26 @@ public class AppointmentsViewModel extends AndroidViewModel {
|
||||
apps.add(doc.toObject(Appointment.class));
|
||||
}
|
||||
}
|
||||
|
||||
// Sort locally
|
||||
apps.sort((a, b) -> {
|
||||
try {
|
||||
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm",
|
||||
java.util.Locale.getDefault());
|
||||
java.util.Date dateA = format.parse(a.date + " " + a.time);
|
||||
java.util.Date dateB = format.parse(b.date + " " + b.time);
|
||||
return dateA.compareTo(dateB);
|
||||
} catch (java.text.ParseException e) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
futureAppointments.setValue(apps);
|
||||
});
|
||||
|
||||
// 2. Fetch Past Appointments
|
||||
db.collection("users").document(userId).collection("appointments")
|
||||
.whereEqualTo("isPast", true)
|
||||
.orderBy("date", Query.Direction.DESCENDING)
|
||||
.orderBy("time", Query.Direction.DESCENDING)
|
||||
.addSnapshotListener((value, error) -> {
|
||||
if (error != null) {
|
||||
Log.e("AppointmentsVM", "Listen failed for past.", error);
|
||||
@@ -72,6 +82,20 @@ public class AppointmentsViewModel extends AndroidViewModel {
|
||||
apps.add(doc.toObject(Appointment.class));
|
||||
}
|
||||
}
|
||||
|
||||
// Sort locally descending
|
||||
apps.sort((a, b) -> {
|
||||
try {
|
||||
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm",
|
||||
java.util.Locale.getDefault());
|
||||
java.util.Date dateA = format.parse(a.date + " " + a.time);
|
||||
java.util.Date dateB = format.parse(b.date + " " + b.time);
|
||||
return dateB.compareTo(dateA); // Reverse for descending
|
||||
} catch (java.text.ParseException e) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
pastAppointments.setValue(apps);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
String email = binding.emailEditText.getText().toString();
|
||||
String password = binding.passwordEditText.getText().toString();
|
||||
|
||||
if (email.equals("admin") && password.equals("123")) {
|
||||
/* if (email.equals("admin") && password.equals("123")) {
|
||||
SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
|
||||
prefs.edit().putBoolean("is_logged_in", true).apply();
|
||||
// Mock data for admin
|
||||
@@ -69,7 +69,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (email.isEmpty() || password.isEmpty()) {
|
||||
Toast.makeText(this, "Preencha todos os campos", Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -55,16 +55,15 @@ public class RegisterActivity extends AppCompatActivity {
|
||||
|
||||
java.util.Map<String, Object> userMap = new java.util.HashMap<>();
|
||||
userMap.put("uid", userId);
|
||||
userMap.put("name", name);
|
||||
userMap.put("nome_completo", name);
|
||||
userMap.put("email", email);
|
||||
userMap.put("age", age);
|
||||
userMap.put("utenteNumber", utenteStr);
|
||||
userMap.put("idade", age);
|
||||
userMap.put("numero_utente", utenteStr);
|
||||
userMap.put("profilePictureUri", ""); // Init empty
|
||||
|
||||
db.collection("users").document(userId)
|
||||
db.collection("usuarios").document(userId)
|
||||
.set(userMap)
|
||||
.addOnSuccessListener(aVoid -> {
|
||||
|
||||
Toast.makeText(RegisterActivity.this, "Conta criada com sucesso!",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
|
||||
|
||||
@@ -45,6 +45,12 @@ public class ScheduleAppointmentFragment extends Fragment {
|
||||
com.google.android.material.textfield.TextInputEditText editReason = getView()
|
||||
.findViewById(R.id.edit_reason);
|
||||
String reason = editReason.getText().toString();
|
||||
|
||||
if (scheduleViewModel.getSelectedTime().getValue() == null) {
|
||||
Toast.makeText(getContext(), "Por favor selecione um horário", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (reason.isEmpty()) {
|
||||
Toast.makeText(getContext(), "Por favor indique o motivo", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
|
||||
@@ -67,6 +67,10 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
}
|
||||
|
||||
private void loadTimeSlots(String date) {
|
||||
// Init slots immediately to prevent "disappearing" hours while waiting for
|
||||
// network.
|
||||
timeSlots.setValue(generateTimeSlots(new ArrayList<>()));
|
||||
|
||||
if (auth.getCurrentUser() == null)
|
||||
return;
|
||||
String userId = auth.getCurrentUser().getUid();
|
||||
@@ -87,8 +91,6 @@ public class ScheduleViewModel extends AndroidViewModel {
|
||||
timeSlots.setValue(slots);
|
||||
} else {
|
||||
Log.e("ScheduleViewModel", "Error getting booked slots", task.getException());
|
||||
List<TimeSlot> slots = generateTimeSlots(new ArrayList<>());
|
||||
timeSlots.setValue(slots);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user