Added null checks for Appointment and Adoptions to make sure the spinner can load
This commit is contained in:
@@ -225,9 +225,16 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
try { fee = new BigDecimal(feeStr); } catch (NumberFormatException ignored) {}
|
||||
}
|
||||
|
||||
DropdownDTO customer = viewModel.getCustomerList().getValue().get(binding.spinnerAdoptionCustomer.getSelectedItemPosition() - 1);
|
||||
DropdownDTO pet = viewModel.getPetList().getValue().get(binding.spinnerAdoptionPet.getSelectedItemPosition() - 1);
|
||||
DropdownDTO store = viewModel.getStoreList().getValue().get(binding.spinnerAdoptionStore.getSelectedItemPosition() - 1);
|
||||
List<DropdownDTO> customerListVal = viewModel.getCustomerList().getValue();
|
||||
List<DropdownDTO> petListVal = viewModel.getPetList().getValue();
|
||||
List<DropdownDTO> storeListVal = viewModel.getStoreList().getValue();
|
||||
if (customerListVal == null || petListVal == null || storeListVal == null) {
|
||||
Toast.makeText(getContext(), "Data not loaded yet, please try again", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
DropdownDTO customer = customerListVal.get(binding.spinnerAdoptionCustomer.getSelectedItemPosition() - 1);
|
||||
DropdownDTO pet = petListVal.get(binding.spinnerAdoptionPet.getSelectedItemPosition() - 1);
|
||||
DropdownDTO store = storeListVal.get(binding.spinnerAdoptionStore.getSelectedItemPosition() - 1);
|
||||
|
||||
Long employeeId = null;
|
||||
if (binding.spinnerAdoptionEmployee.getSelectedItemPosition() > 0 && viewModel.getEmployeeList().getValue() != null) {
|
||||
|
||||
@@ -248,7 +248,12 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
|
||||
String date = binding.etAppointmentDate.getText().toString().trim();
|
||||
String time = buildTimeString();
|
||||
String status = binding.spinnerAppointmentStatus.getSelectedItem().toString().toUpperCase();
|
||||
Object selectedStatus = binding.spinnerAppointmentStatus.getSelectedItem();
|
||||
if (selectedStatus == null) {
|
||||
Toast.makeText(getContext(), "Please select a status", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
String status = selectedStatus.toString().toUpperCase();
|
||||
|
||||
if (!viewModel.isValidFutureBooking(status, date, time)) {
|
||||
DialogUtils.showInfoDialog(requireContext(), "Invalid Time", "Booked appointments must be in the future.");
|
||||
|
||||
@@ -248,10 +248,10 @@ public class AdoptionDetailViewModel extends ViewModel {
|
||||
String adoptionDate = a.getAdoptionDate() != null ? a.getAdoptionDate() : "";
|
||||
|
||||
updateViewState(state -> {
|
||||
state.selectedPetId = a.getPetId() != null ? a.getPetId() : -1;
|
||||
state.selectedCustomerId = a.getCustomerId() != null ? a.getCustomerId() : -1;
|
||||
state.selectedStoreId = a.getSourceStoreId() != null ? a.getSourceStoreId() : -1;
|
||||
state.selectedEmployeeId = a.getEmployeeId() != null ? a.getEmployeeId() : -1;
|
||||
state.selectedPetId = a.getPetId();
|
||||
state.selectedCustomerId = a.getCustomerId();
|
||||
state.selectedStoreId = a.getSourceStoreId();
|
||||
state.selectedEmployeeId = a.getEmployeeId();
|
||||
state.adoptionDate = adoptionDate;
|
||||
state.adoptionFee = a.getAdoptionFee() != null ? a.getAdoptionFee().toPlainString() : "";
|
||||
state.selectedStatus = formattedStatus;
|
||||
|
||||
@@ -72,13 +72,13 @@ public class AppointmentDetailViewModel extends ViewModel {
|
||||
*/
|
||||
public void loadInitialFormData() {
|
||||
customerRepository.getCustomerDropdowns().observeForever(r -> {
|
||||
if (r.status == Resource.Status.SUCCESS) customers.setValue(r.data);
|
||||
if (r != null && r.status == Resource.Status.SUCCESS) customers.setValue(r.data);
|
||||
});
|
||||
storeRepository.getStoreDropdowns().observeForever(r -> {
|
||||
if (r.status == Resource.Status.SUCCESS) stores.setValue(r.data);
|
||||
if (r != null && r.status == Resource.Status.SUCCESS) stores.setValue(r.data);
|
||||
});
|
||||
serviceRepository.getAllServices(0, 200, null, "serviceName").observeForever(r -> {
|
||||
if (r.status == Resource.Status.SUCCESS && r.data != null) services.setValue(r.data.getContent());
|
||||
if (r != null && r.status == Resource.Status.SUCCESS && r.data != null) services.setValue(r.data.getContent());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public class AppointmentDetailViewModel extends ViewModel {
|
||||
*/
|
||||
private void loadPetsForCustomer(Long customerId) {
|
||||
petRepository.getCustomerPets(customerId).observeForever(r -> {
|
||||
if (r.status == Resource.Status.SUCCESS) customerPets.setValue(r.data);
|
||||
if (r != null && r.status == Resource.Status.SUCCESS) customerPets.setValue(r.data);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class AppointmentDetailViewModel extends ViewModel {
|
||||
*/
|
||||
private void loadEmployeesForStore(Long storeId) {
|
||||
storeRepository.getStoreEmployees(storeId).observeForever(r -> {
|
||||
if (r.status == Resource.Status.SUCCESS) storeEmployees.setValue(r.data);
|
||||
if (r != null && r.status == Resource.Status.SUCCESS) storeEmployees.setValue(r.data);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ public class AppointmentDetailViewModel extends ViewModel {
|
||||
public LiveData<Resource<AppointmentDTO>> loadAppointment() {
|
||||
MutableLiveData<Resource<AppointmentDTO>> result = new MutableLiveData<>();
|
||||
repository.getAppointmentById(appointmentId).observeForever(resource -> {
|
||||
if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
||||
if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
||||
AppointmentDTO a = resource.data;
|
||||
isOriginallyCancel = "CANCELLED".equalsIgnoreCase(a.getAppointmentStatus());
|
||||
currentCustomerId = a.getCustomerId();
|
||||
|
||||
Reference in New Issue
Block a user