fixing dropdowns
This commit is contained in:
@@ -44,7 +44,7 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
private List<DropdownDTO> petList = new ArrayList<>();
|
||||
private List<DropdownDTO> customerList = new ArrayList<>();
|
||||
private List<DropdownDTO> storeList = new ArrayList<>();
|
||||
private List<UserDTO> employeeList = new ArrayList<>();
|
||||
private List<DropdownDTO> employeeList = new ArrayList<>();
|
||||
|
||||
private final String[] STATUSES = {"Pending", "Completed", "Cancelled"};
|
||||
|
||||
@@ -95,6 +95,46 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
*/
|
||||
private void setupSpinners() {
|
||||
SpinnerUtils.setupStringSpinner(requireContext(), binding.spinnerAdoptionStatus, STATUSES);
|
||||
|
||||
// Pet spinner disabled by default until customer is selected
|
||||
binding.spinnerAdoptionPet.setEnabled(false);
|
||||
binding.spinnerAdoptionPet.setAlpha(0.5f);
|
||||
|
||||
// Listener to enable pet spinner based on customer selection
|
||||
binding.spinnerAdoptionCustomer.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (position > 0) {
|
||||
binding.spinnerAdoptionPet.setEnabled(true);
|
||||
binding.spinnerAdoptionPet.setAlpha(1.0f);
|
||||
} else {
|
||||
if (!isEditing) {
|
||||
binding.spinnerAdoptionPet.setSelection(0);
|
||||
binding.spinnerAdoptionPet.setEnabled(false);
|
||||
binding.spinnerAdoptionPet.setAlpha(0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
// Listener to load employees based on selected store
|
||||
binding.spinnerAdoptionStore.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (position > 0 && position <= storeList.size()) {
|
||||
DropdownDTO selectedStore = storeList.get(position - 1);
|
||||
loadEmployees(selectedStore.getId());
|
||||
} else {
|
||||
employeeList.clear();
|
||||
refreshEmployeeSpinner();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +159,6 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
loadPets();
|
||||
loadCustomers();
|
||||
loadStores();
|
||||
loadEmployees();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,12 +226,12 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the list of employees from the API.
|
||||
* Loads the list of employees for a specific store.
|
||||
*/
|
||||
private void loadEmployees() {
|
||||
userViewModel.getUsers("STAFF", 0, 100).observe(getViewLifecycleOwner(), resource -> {
|
||||
if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
||||
employeeList = resource.data.getContent();
|
||||
private void loadEmployees(Long storeId) {
|
||||
storeViewModel.getStoreEmployees(storeId).observe(getViewLifecycleOwner(), resource -> {
|
||||
if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
||||
employeeList = resource.data;
|
||||
refreshEmployeeSpinner();
|
||||
}
|
||||
});
|
||||
@@ -203,8 +242,8 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
*/
|
||||
private void refreshEmployeeSpinner() {
|
||||
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerAdoptionEmployee, employeeList,
|
||||
UserDTO::getFullName, "-- Select Staff --",
|
||||
preselectedEmployeeId, UserDTO::getId);
|
||||
DropdownDTO::getLabel, "-- Select Staff --",
|
||||
preselectedEmployeeId, DropdownDTO::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,9 +260,14 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
binding.btnDeleteAdoption.setVisibility(View.VISIBLE);
|
||||
loadAdoptionData();
|
||||
} else {
|
||||
isEditing = false;
|
||||
binding.tvAdoptionMode.setText("Add Adoption");
|
||||
binding.btnDeleteAdoption.setVisibility(View.GONE);
|
||||
binding.tvAdoptionId.setVisibility(View.GONE);
|
||||
|
||||
// Explicitly disable in add mode
|
||||
binding.spinnerAdoptionPet.setEnabled(false);
|
||||
binding.spinnerAdoptionPet.setAlpha(0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +291,12 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
refreshPetSpinner();
|
||||
refreshCustomerSpinner();
|
||||
refreshStoreSpinner();
|
||||
refreshEmployeeSpinner();
|
||||
|
||||
// In edit mode, if a customer is already set, ensure pet spinner is enabled
|
||||
if (preselectedCustomerId != -1) {
|
||||
binding.spinnerAdoptionPet.setEnabled(true);
|
||||
binding.spinnerAdoptionPet.setAlpha(1.0f);
|
||||
}
|
||||
} else if (resource.status == Resource.Status.ERROR) {
|
||||
Toast.makeText(getContext(), "Failed to load adoption: " + resource.message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@@ -108,6 +108,10 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
SpinnerUtils.setupStringSpinner(requireContext(), binding.spinnerHour, hours);
|
||||
SpinnerUtils.setupStringSpinner(requireContext(), binding.spinnerMinute, new String[]{"00","15","30","45"});
|
||||
|
||||
// Pet spinner disabled by default
|
||||
binding.spinnerPet.setEnabled(false);
|
||||
binding.spinnerPet.setAlpha(0.5f);
|
||||
|
||||
// Listener to load pets based on selected customer
|
||||
binding.spinnerCustomer.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
@@ -115,9 +119,18 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
if (position > 0 && position <= customerList.size()) {
|
||||
DropdownDTO selectedCustomer = customerList.get(position - 1);
|
||||
loadPets(selectedCustomer.getId());
|
||||
if (!isEditing) {
|
||||
binding.spinnerPet.setEnabled(true);
|
||||
binding.spinnerPet.setAlpha(1.0f);
|
||||
}
|
||||
} else {
|
||||
petList.clear();
|
||||
refreshPetSpinner();
|
||||
if (!isEditing) {
|
||||
binding.spinnerPet.setSelection(0);
|
||||
binding.spinnerPet.setEnabled(false);
|
||||
binding.spinnerPet.setAlpha(0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,6 +293,7 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
private void handleArguments() {
|
||||
Bundle a = getArguments();
|
||||
if (a != null && a.containsKey("appointmentId")) {
|
||||
//edit mode
|
||||
isEditing = true;
|
||||
appointmentId = a.getLong("appointmentId");
|
||||
binding.tvApptMode.setText("Edit Appointment");
|
||||
@@ -287,7 +301,6 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
binding.tvAppointmentId.setVisibility(View.VISIBLE);
|
||||
binding.btnDeleteAppointment.setVisibility(View.VISIBLE);
|
||||
|
||||
// Disable and fade fields in edit mode
|
||||
binding.spinnerCustomer.setEnabled(false);
|
||||
binding.spinnerStore.setEnabled(false);
|
||||
binding.spinnerPet.setEnabled(false);
|
||||
@@ -304,18 +317,18 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
|
||||
loadAppointmentData();
|
||||
} else {
|
||||
//add mode
|
||||
binding.tvApptMode.setText("Add Appointment");
|
||||
binding.btnDeleteAppointment.setVisibility(View.GONE);
|
||||
binding.tvAppointmentId.setVisibility(View.GONE);
|
||||
|
||||
// enable fields in add mode
|
||||
binding.spinnerCustomer.setEnabled(true);
|
||||
binding.spinnerStore.setEnabled(true);
|
||||
binding.spinnerPet.setEnabled(true);
|
||||
binding.spinnerPet.setEnabled(false);
|
||||
binding.spinnerPet.setAlpha(0.5f);
|
||||
binding.spinnerService.setEnabled(true);
|
||||
binding.spinnerCustomer.setAlpha(1.0f);
|
||||
binding.spinnerStore.setAlpha(1.0f);
|
||||
binding.spinnerPet.setAlpha(1.0f);
|
||||
binding.spinnerService.setAlpha(1.0f);
|
||||
|
||||
binding.tvLabelCustomer.setAlpha(1.0f);
|
||||
|
||||
Reference in New Issue
Block a user