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) {}
|
try { fee = new BigDecimal(feeStr); } catch (NumberFormatException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
DropdownDTO customer = viewModel.getCustomerList().getValue().get(binding.spinnerAdoptionCustomer.getSelectedItemPosition() - 1);
|
List<DropdownDTO> customerListVal = viewModel.getCustomerList().getValue();
|
||||||
DropdownDTO pet = viewModel.getPetList().getValue().get(binding.spinnerAdoptionPet.getSelectedItemPosition() - 1);
|
List<DropdownDTO> petListVal = viewModel.getPetList().getValue();
|
||||||
DropdownDTO store = viewModel.getStoreList().getValue().get(binding.spinnerAdoptionStore.getSelectedItemPosition() - 1);
|
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;
|
Long employeeId = null;
|
||||||
if (binding.spinnerAdoptionEmployee.getSelectedItemPosition() > 0 && viewModel.getEmployeeList().getValue() != 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 date = binding.etAppointmentDate.getText().toString().trim();
|
||||||
String time = buildTimeString();
|
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)) {
|
if (!viewModel.isValidFutureBooking(status, date, time)) {
|
||||||
DialogUtils.showInfoDialog(requireContext(), "Invalid Time", "Booked appointments must be in the future.");
|
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() : "";
|
String adoptionDate = a.getAdoptionDate() != null ? a.getAdoptionDate() : "";
|
||||||
|
|
||||||
updateViewState(state -> {
|
updateViewState(state -> {
|
||||||
state.selectedPetId = a.getPetId() != null ? a.getPetId() : -1;
|
state.selectedPetId = a.getPetId();
|
||||||
state.selectedCustomerId = a.getCustomerId() != null ? a.getCustomerId() : -1;
|
state.selectedCustomerId = a.getCustomerId();
|
||||||
state.selectedStoreId = a.getSourceStoreId() != null ? a.getSourceStoreId() : -1;
|
state.selectedStoreId = a.getSourceStoreId();
|
||||||
state.selectedEmployeeId = a.getEmployeeId() != null ? a.getEmployeeId() : -1;
|
state.selectedEmployeeId = a.getEmployeeId();
|
||||||
state.adoptionDate = adoptionDate;
|
state.adoptionDate = adoptionDate;
|
||||||
state.adoptionFee = a.getAdoptionFee() != null ? a.getAdoptionFee().toPlainString() : "";
|
state.adoptionFee = a.getAdoptionFee() != null ? a.getAdoptionFee().toPlainString() : "";
|
||||||
state.selectedStatus = formattedStatus;
|
state.selectedStatus = formattedStatus;
|
||||||
|
|||||||
@@ -72,13 +72,13 @@ public class AppointmentDetailViewModel extends ViewModel {
|
|||||||
*/
|
*/
|
||||||
public void loadInitialFormData() {
|
public void loadInitialFormData() {
|
||||||
customerRepository.getCustomerDropdowns().observeForever(r -> {
|
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 -> {
|
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 -> {
|
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) {
|
private void loadPetsForCustomer(Long customerId) {
|
||||||
petRepository.getCustomerPets(customerId).observeForever(r -> {
|
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) {
|
private void loadEmployeesForStore(Long storeId) {
|
||||||
storeRepository.getStoreEmployees(storeId).observeForever(r -> {
|
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() {
|
public LiveData<Resource<AppointmentDTO>> loadAppointment() {
|
||||||
MutableLiveData<Resource<AppointmentDTO>> result = new MutableLiveData<>();
|
MutableLiveData<Resource<AppointmentDTO>> result = new MutableLiveData<>();
|
||||||
repository.getAppointmentById(appointmentId).observeForever(resource -> {
|
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;
|
AppointmentDTO a = resource.data;
|
||||||
isOriginallyCancel = "CANCELLED".equalsIgnoreCase(a.getAppointmentStatus());
|
isOriginallyCancel = "CANCELLED".equalsIgnoreCase(a.getAppointmentStatus());
|
||||||
currentCustomerId = a.getCustomerId();
|
currentCustomerId = a.getCustomerId();
|
||||||
|
|||||||
Reference in New Issue
Block a user