fixed bug on appointments where spinners was not populating the correct data
This commit is contained in:
@@ -44,6 +44,7 @@ public class AppointmentDetailViewModel extends ViewModel {
|
|||||||
|
|
||||||
private long appointmentId = -1;
|
private long appointmentId = -1;
|
||||||
private boolean isOriginallyCancel = false;
|
private boolean isOriginallyCancel = false;
|
||||||
|
private boolean isOriginallyCompletedOrMissed = false;
|
||||||
private Long currentCustomerId;
|
private Long currentCustomerId;
|
||||||
private Long currentStoreId;
|
private Long currentStoreId;
|
||||||
private Long currentPetId;
|
private Long currentPetId;
|
||||||
@@ -233,6 +234,8 @@ public class AppointmentDetailViewModel extends ViewModel {
|
|||||||
if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
||||||
AppointmentDTO a = resource.data;
|
AppointmentDTO a = resource.data;
|
||||||
isOriginallyCancel = "CANCELLED".equalsIgnoreCase(a.getAppointmentStatus());
|
isOriginallyCancel = "CANCELLED".equalsIgnoreCase(a.getAppointmentStatus());
|
||||||
|
isOriginallyCompletedOrMissed = "COMPLETED".equalsIgnoreCase(a.getAppointmentStatus())
|
||||||
|
|| "MISSED".equalsIgnoreCase(a.getAppointmentStatus());
|
||||||
currentCustomerId = a.getCustomerId();
|
currentCustomerId = a.getCustomerId();
|
||||||
currentStoreId = a.getStoreId();
|
currentStoreId = a.getStoreId();
|
||||||
currentPetId = a.getPetId();
|
currentPetId = a.getPetId();
|
||||||
@@ -284,21 +287,18 @@ public class AppointmentDetailViewModel extends ViewModel {
|
|||||||
public void onDateOrTimeChanged(String date, String time, String currentStatus) {
|
public void onDateOrTimeChanged(String date, String time, String currentStatus) {
|
||||||
updateViewState(s -> {
|
updateViewState(s -> {
|
||||||
s.availableStatuses = calculateAvailableStatuses(s.isEditing, date, time, currentStatus);
|
s.availableStatuses = calculateAvailableStatuses(s.isEditing, date, time, currentStatus);
|
||||||
// Keep selectedStatus if still valid; prefer explicit currentStatus from UI if valid
|
|
||||||
java.util.List<String> available = java.util.Arrays.asList(s.availableStatuses);
|
java.util.List<String> available = java.util.Arrays.asList(s.availableStatuses);
|
||||||
if (!currentStatus.isEmpty() && available.contains(currentStatus)) {
|
if (!currentStatus.isEmpty() && available.contains(currentStatus)) {
|
||||||
s.selectedStatus = currentStatus;
|
s.selectedStatus = currentStatus;
|
||||||
} else if (!available.contains(s.selectedStatus) && s.availableStatuses.length > 0) {
|
} else if (!available.contains(s.selectedStatus) && s.availableStatuses.length > 0) {
|
||||||
s.selectedStatus = s.availableStatuses[0];
|
s.selectedStatus = s.availableStatuses[0];
|
||||||
}
|
}
|
||||||
boolean isPast = DateTimeUtils.isDateTimeInPast(date, time);
|
|
||||||
|
|
||||||
if (isOriginallyCancel) {
|
if (isOriginallyCancel) {
|
||||||
s.isPast = true;
|
s.isPast = true;
|
||||||
setAllFieldsEnabled(s, false);
|
setAllFieldsEnabled(s, false);
|
||||||
s.isStatusEnabled = false;
|
s.isStatusEnabled = false;
|
||||||
s.isSaveVisible = false;
|
s.isSaveVisible = false;
|
||||||
} else if (isPast) {
|
} else if (isOriginallyCompletedOrMissed) {
|
||||||
s.isPast = true;
|
s.isPast = true;
|
||||||
setAllFieldsEnabled(s, false);
|
setAllFieldsEnabled(s, false);
|
||||||
s.isStatusEnabled = true;
|
s.isStatusEnabled = true;
|
||||||
@@ -324,7 +324,7 @@ public class AppointmentDetailViewModel extends ViewModel {
|
|||||||
if (!isEditing) return new String[]{"Booked"};
|
if (!isEditing) return new String[]{"Booked"};
|
||||||
if (date == null || date.isEmpty()) return new String[]{};
|
if (date == null || date.isEmpty()) return new String[]{};
|
||||||
if (isOriginallyCancel) return new String[]{"Cancelled"};
|
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"};
|
return new String[]{"Booked", "Cancelled"};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,8 +357,8 @@ public class AppointmentDetailViewModel extends ViewModel {
|
|||||||
s.isCustomerEnabled = true;
|
s.isCustomerEnabled = true;
|
||||||
s.isStoreEnabled = true;
|
s.isStoreEnabled = true;
|
||||||
s.isServiceEnabled = true;
|
s.isServiceEnabled = true;
|
||||||
s.isPetEnabled = false; // until customer selected
|
s.isPetEnabled = false;
|
||||||
s.isStaffEnabled = false; // until store selected
|
s.isStaffEnabled = false;
|
||||||
s.availableStatuses = new String[]{"Booked"};
|
s.availableStatuses = new String[]{"Booked"};
|
||||||
s.selectedStatus = "Booked";
|
s.selectedStatus = "Booked";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user