updated Appointments on andriod for new backend
This commit is contained in:
@@ -59,14 +59,14 @@ public class AppointmentAdapter extends RecyclerView.Adapter<AppointmentAdapter.
|
|||||||
String status = a.getStatus() != null ? a.getStatus() : "";
|
String status = a.getStatus() != null ? a.getStatus() : "";
|
||||||
holder.tvAppointmentStatus.setText(status);
|
holder.tvAppointmentStatus.setText(status);
|
||||||
|
|
||||||
switch (status) {
|
switch (status.toUpperCase()) {
|
||||||
case "Booked":
|
case "BOOKED":
|
||||||
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#2196F3")); // blue
|
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#2196F3")); // blue
|
||||||
break;
|
break;
|
||||||
case "Completed":
|
case "COMPLETED":
|
||||||
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#4CAF50")); // green
|
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#4CAF50")); // green
|
||||||
break;
|
break;
|
||||||
case "Cancelled":
|
case "CANCELLED":
|
||||||
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#F44336")); // red
|
holder.tvAppointmentStatus.setBackgroundColor(Color.parseColor("#F44336")); // red
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package com.example.petstoremobile.dtos;
|
package com.example.petstoremobile.dtos;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AppointmentDTO {
|
public class AppointmentDTO {
|
||||||
|
|
||||||
private Long appointmentId;
|
private Long appointmentId;
|
||||||
@@ -17,20 +14,20 @@ public class AppointmentDTO {
|
|||||||
private String appointmentDate;
|
private String appointmentDate;
|
||||||
private String appointmentTime;
|
private String appointmentTime;
|
||||||
private String appointmentStatus;
|
private String appointmentStatus;
|
||||||
private List<String> petNames;
|
private String petName;
|
||||||
private List<Long> petIds;
|
private Long petId;
|
||||||
private String createdAt;
|
private String createdAt;
|
||||||
private String updatedAt;
|
private String updatedAt;
|
||||||
|
|
||||||
public AppointmentDTO(Long customerId, Long storeId, Long serviceId,
|
public AppointmentDTO(Long customerId, Long storeId, Long serviceId,
|
||||||
String appointmentDate, String appointmentTime,
|
String appointmentDate, String appointmentTime,
|
||||||
String appointmentStatus, List<Long> petIds) {
|
String appointmentStatus, Long petId) {
|
||||||
this(customerId, storeId, serviceId, null, appointmentDate, appointmentTime, appointmentStatus, petIds);
|
this(customerId, storeId, serviceId, null, appointmentDate, appointmentTime, appointmentStatus, petId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AppointmentDTO(Long customerId, Long storeId, Long serviceId, Long employeeId,
|
public AppointmentDTO(Long customerId, Long storeId, Long serviceId, Long employeeId,
|
||||||
String appointmentDate, String appointmentTime,
|
String appointmentDate, String appointmentTime,
|
||||||
String appointmentStatus, List<Long> petIds) {
|
String appointmentStatus, Long petId) {
|
||||||
this.customerId = customerId;
|
this.customerId = customerId;
|
||||||
this.storeId = storeId;
|
this.storeId = storeId;
|
||||||
this.serviceId = serviceId;
|
this.serviceId = serviceId;
|
||||||
@@ -38,7 +35,7 @@ public class AppointmentDTO {
|
|||||||
this.appointmentDate = appointmentDate;
|
this.appointmentDate = appointmentDate;
|
||||||
this.appointmentTime = appointmentTime;
|
this.appointmentTime = appointmentTime;
|
||||||
this.appointmentStatus = appointmentStatus;
|
this.appointmentStatus = appointmentStatus;
|
||||||
this.petIds = petIds;
|
this.petId = petId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getAppointmentId() {
|
public Long getAppointmentId() {
|
||||||
@@ -89,12 +86,12 @@ public class AppointmentDTO {
|
|||||||
return appointmentStatus;
|
return appointmentStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPetNames() {
|
public String getPetName() {
|
||||||
return petNames;
|
return petName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Long> getPetIds() {
|
public Long getPetId() {
|
||||||
return petIds;
|
return petId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreatedAt() {
|
public String getCreatedAt() {
|
||||||
@@ -105,16 +102,8 @@ public class AppointmentDTO {
|
|||||||
return updatedAt;
|
return updatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPetName() {
|
|
||||||
return (petNames != null && !petNames.isEmpty()) ? petNames.get(0) : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getPetID() {
|
public Long getPetID() {
|
||||||
return (petIds != null && !petIds.isEmpty()) ? petIds.get(0) : null;
|
return petId;
|
||||||
}
|
|
||||||
|
|
||||||
public Long getPetId() {
|
|
||||||
return getPetID();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServiceType() {
|
public String getServiceType() {
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ public class AppointmentDetailFragment extends Fragment {
|
|||||||
|
|
||||||
private final Integer[] HOURS = {9,10,11,12,13,14,15,16,17};
|
private final Integer[] HOURS = {9,10,11,12,13,14,15,16,17};
|
||||||
private final Integer[] MINUTES = {0,15,30,45};
|
private final Integer[] MINUTES = {0,15,30,45};
|
||||||
private final String[] STATUSES = {"Booked","Completed","Cancelled"};
|
|
||||||
|
|
||||||
private AppointmentViewModel appointmentViewModel;
|
private AppointmentViewModel appointmentViewModel;
|
||||||
private PetViewModel petViewModel;
|
private PetViewModel petViewModel;
|
||||||
@@ -95,7 +94,8 @@ public class AppointmentDetailFragment extends Fragment {
|
|||||||
* Configures the adapters for spinners.
|
* Configures the adapters for spinners.
|
||||||
*/
|
*/
|
||||||
private void setupSpinners() {
|
private void setupSpinners() {
|
||||||
SpinnerUtils.setupStringSpinner(requireContext(), binding.spinnerAppointmentStatus, STATUSES);
|
SpinnerUtils.setupStringSpinner(requireContext(), binding.spinnerAppointmentStatus,
|
||||||
|
new String[]{"Booked", "Completed", "Cancelled", "Missed"});
|
||||||
|
|
||||||
String[] hours = new String[HOURS.length];
|
String[] hours = new String[HOURS.length];
|
||||||
for (int i = 0; i < HOURS.length; i++)
|
for (int i = 0; i < HOURS.length; i++)
|
||||||
@@ -243,7 +243,7 @@ public class AppointmentDetailFragment extends Fragment {
|
|||||||
if (resource == null) return;
|
if (resource == null) return;
|
||||||
if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
||||||
AppointmentDTO a = resource.data;
|
AppointmentDTO a = resource.data;
|
||||||
preselectedPetId = (a.getPetID() != null) ? a.getPetID() : -1;
|
preselectedPetId = (a.getPetId() != null) ? a.getPetId() : -1;
|
||||||
preselectedServiceId = (a.getServiceId() != null) ? a.getServiceId() : -1;
|
preselectedServiceId = (a.getServiceId() != null) ? a.getServiceId() : -1;
|
||||||
preselectedCustomerId = (a.getCustomerId() != null) ? a.getCustomerId() : -1;
|
preselectedCustomerId = (a.getCustomerId() != null) ? a.getCustomerId() : -1;
|
||||||
preselectedStoreId = (a.getStoreId() != null) ? a.getStoreId() : -1;
|
preselectedStoreId = (a.getStoreId() != null) ? a.getStoreId() : -1;
|
||||||
@@ -265,7 +265,12 @@ public class AppointmentDetailFragment extends Fragment {
|
|||||||
} catch (NumberFormatException ignored) {}
|
} catch (NumberFormatException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpinnerUtils.setSelectionByValue(binding.spinnerAppointmentStatus, a.getAppointmentStatus());
|
// Match Title labels with backend values
|
||||||
|
String status = a.getAppointmentStatus();
|
||||||
|
if (status != null && !status.isEmpty()) {
|
||||||
|
String formattedStatus = status.substring(0, 1).toUpperCase() + status.substring(1).toLowerCase();
|
||||||
|
SpinnerUtils.setSelectionByValue(binding.spinnerAppointmentStatus, formattedStatus);
|
||||||
|
}
|
||||||
|
|
||||||
refreshPetSpinner();
|
refreshPetSpinner();
|
||||||
refreshServiceSpinner();
|
refreshServiceSpinner();
|
||||||
@@ -306,11 +311,13 @@ public class AppointmentDetailFragment extends Fragment {
|
|||||||
String time = String.format("%02d:%02d",
|
String time = String.format("%02d:%02d",
|
||||||
HOURS[binding.spinnerHour.getSelectedItemPosition()],
|
HOURS[binding.spinnerHour.getSelectedItemPosition()],
|
||||||
MINUTES[binding.spinnerMinute.getSelectedItemPosition()]);
|
MINUTES[binding.spinnerMinute.getSelectedItemPosition()]);
|
||||||
String status = STATUSES[binding.spinnerAppointmentStatus.getSelectedItemPosition()];
|
|
||||||
|
// Get status and convert to uppercase for backend
|
||||||
|
String status = binding.spinnerAppointmentStatus.getSelectedItem().toString().toUpperCase();
|
||||||
|
|
||||||
|
|
||||||
// Validate future date+time if status is Booked
|
// Validate future date+time if status is BOOKED
|
||||||
if ("Booked".equalsIgnoreCase(status)) {
|
if ("BOOKED".equalsIgnoreCase(status)) {
|
||||||
try {
|
try {
|
||||||
String[] dateParts = date.split("-");
|
String[] dateParts = date.split("-");
|
||||||
String[] timeParts = time.split(":");
|
String[] timeParts = time.split(":");
|
||||||
@@ -342,7 +349,7 @@ public class AppointmentDetailFragment extends Fragment {
|
|||||||
date,
|
date,
|
||||||
time,
|
time,
|
||||||
status,
|
status,
|
||||||
Collections.singletonList(pet.getPetId())
|
pet.getPetId()
|
||||||
);
|
);
|
||||||
|
|
||||||
androidx.lifecycle.Observer<Resource<AppointmentDTO>> observer = resource -> {
|
androidx.lifecycle.Observer<Resource<AppointmentDTO>> observer = resource -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user