From 6245fa88da5b7943fad4c23a3582276824a0d65e Mon Sep 17 00:00:00 2001 From: Alex <78383757+Lextical@users.noreply.github.com> Date: Sat, 11 Apr 2026 22:02:06 -0600 Subject: [PATCH] fixed bug on appointments where spinners was not populating the correct data --- .../viewmodels/AppointmentDetailViewModel.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/android/app/src/main/java/com/example/petstoremobile/viewmodels/AppointmentDetailViewModel.java b/android/app/src/main/java/com/example/petstoremobile/viewmodels/AppointmentDetailViewModel.java index c70c1895..b229c3a0 100644 --- a/android/app/src/main/java/com/example/petstoremobile/viewmodels/AppointmentDetailViewModel.java +++ b/android/app/src/main/java/com/example/petstoremobile/viewmodels/AppointmentDetailViewModel.java @@ -44,6 +44,7 @@ public class AppointmentDetailViewModel extends ViewModel { private long appointmentId = -1; private boolean isOriginallyCancel = false; + private boolean isOriginallyCompletedOrMissed = false; private Long currentCustomerId; private Long currentStoreId; private Long currentPetId; @@ -233,6 +234,8 @@ public class AppointmentDetailViewModel extends ViewModel { if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) { AppointmentDTO a = resource.data; isOriginallyCancel = "CANCELLED".equalsIgnoreCase(a.getAppointmentStatus()); + isOriginallyCompletedOrMissed = "COMPLETED".equalsIgnoreCase(a.getAppointmentStatus()) + || "MISSED".equalsIgnoreCase(a.getAppointmentStatus()); currentCustomerId = a.getCustomerId(); currentStoreId = a.getStoreId(); currentPetId = a.getPetId(); @@ -284,21 +287,18 @@ public class AppointmentDetailViewModel extends ViewModel { public void onDateOrTimeChanged(String date, String time, String currentStatus) { updateViewState(s -> { s.availableStatuses = calculateAvailableStatuses(s.isEditing, date, time, currentStatus); - // Keep selectedStatus if still valid; prefer explicit currentStatus from UI if valid java.util.List available = java.util.Arrays.asList(s.availableStatuses); if (!currentStatus.isEmpty() && available.contains(currentStatus)) { s.selectedStatus = currentStatus; } else if (!available.contains(s.selectedStatus) && s.availableStatuses.length > 0) { s.selectedStatus = s.availableStatuses[0]; } - boolean isPast = DateTimeUtils.isDateTimeInPast(date, time); - if (isOriginallyCancel) { s.isPast = true; setAllFieldsEnabled(s, false); s.isStatusEnabled = false; s.isSaveVisible = false; - } else if (isPast) { + } else if (isOriginallyCompletedOrMissed) { s.isPast = true; setAllFieldsEnabled(s, false); s.isStatusEnabled = true; @@ -324,7 +324,7 @@ public class AppointmentDetailViewModel extends ViewModel { if (!isEditing) return new String[]{"Booked"}; if (date == null || date.isEmpty()) return new String[]{}; if (isOriginallyCancel) return new String[]{"Cancelled"}; - if (DateTimeUtils.isDateTimeInPast(date, currentTime)) return new String[]{"Completed", "Missed"}; + if (isOriginallyCompletedOrMissed) return new String[]{"Completed", "Missed"}; return new String[]{"Booked", "Cancelled"}; } @@ -357,8 +357,8 @@ public class AppointmentDetailViewModel extends ViewModel { s.isCustomerEnabled = true; s.isStoreEnabled = true; s.isServiceEnabled = true; - s.isPetEnabled = false; // until customer selected - s.isStaffEnabled = false; // until store selected + s.isPetEnabled = false; + s.isStaffEnabled = false; s.availableStatuses = new String[]{"Booked"}; s.selectedStatus = "Booked"; }