Close chat #169
@@ -15,6 +15,7 @@ import com.example.petstoremobile.dtos.*;
|
||||
import com.example.petstoremobile.utils.DialogUtils;
|
||||
import com.example.petstoremobile.utils.Resource;
|
||||
import com.example.petstoremobile.utils.SpinnerUtils;
|
||||
import com.example.petstoremobile.utils.UIUtils;
|
||||
import com.example.petstoremobile.viewmodels.AdoptionViewModel;
|
||||
import com.example.petstoremobile.viewmodels.CustomerViewModel;
|
||||
import com.example.petstoremobile.viewmodels.PetViewModel;
|
||||
@@ -97,21 +98,18 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
SpinnerUtils.setupStringSpinner(requireContext(), binding.spinnerAdoptionStatus, STATUSES);
|
||||
|
||||
// Pet spinner disabled by default until customer is selected
|
||||
binding.spinnerAdoptionPet.setEnabled(false);
|
||||
binding.spinnerAdoptionPet.setAlpha(0.5f);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerAdoptionPet);
|
||||
|
||||
// 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);
|
||||
UIUtils.setViewsEnabled(true, binding.spinnerAdoptionPet);
|
||||
} else {
|
||||
if (!isEditing) {
|
||||
binding.spinnerAdoptionPet.setSelection(0);
|
||||
binding.spinnerAdoptionPet.setEnabled(false);
|
||||
binding.spinnerAdoptionPet.setAlpha(0.5f);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerAdoptionPet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,8 +264,7 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
binding.tvAdoptionId.setVisibility(View.GONE);
|
||||
|
||||
// Explicitly disable in add mode
|
||||
binding.spinnerAdoptionPet.setEnabled(false);
|
||||
binding.spinnerAdoptionPet.setAlpha(0.5f);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerAdoptionPet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,8 +291,7 @@ public class AdoptionDetailFragment extends Fragment {
|
||||
|
||||
// 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);
|
||||
UIUtils.setViewsEnabled(true, binding.spinnerAdoptionPet);
|
||||
}
|
||||
} else if (resource.status == Resource.Status.ERROR) {
|
||||
Toast.makeText(getContext(), "Failed to load adoption: " + resource.message, Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.example.petstoremobile.dtos.*;
|
||||
import com.example.petstoremobile.utils.DialogUtils;
|
||||
import com.example.petstoremobile.utils.Resource;
|
||||
import com.example.petstoremobile.utils.SpinnerUtils;
|
||||
import com.example.petstoremobile.utils.UIUtils;
|
||||
import com.example.petstoremobile.viewmodels.AppointmentViewModel;
|
||||
import com.example.petstoremobile.viewmodels.CustomerViewModel;
|
||||
import com.example.petstoremobile.viewmodels.PetViewModel;
|
||||
@@ -109,9 +110,8 @@ 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);
|
||||
// Pet and Staff spinners disabled by until parent selection
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerPet, binding.spinnerStaff);
|
||||
|
||||
// Listener to load pets based on selected customer
|
||||
binding.spinnerCustomer.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@@ -121,16 +121,14 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
DropdownDTO selectedCustomer = customerList.get(position - 1);
|
||||
loadPets(selectedCustomer.getId());
|
||||
if (!isEditing) {
|
||||
binding.spinnerPet.setEnabled(true);
|
||||
binding.spinnerPet.setAlpha(1.0f);
|
||||
UIUtils.setViewsEnabled(true, binding.spinnerPet);
|
||||
}
|
||||
} else {
|
||||
petList.clear();
|
||||
refreshPetSpinner();
|
||||
if (!isEditing) {
|
||||
binding.spinnerPet.setSelection(0);
|
||||
binding.spinnerPet.setEnabled(false);
|
||||
binding.spinnerPet.setAlpha(0.5f);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerPet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,9 +144,16 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
if (position > 0 && position <= storeList.size()) {
|
||||
DropdownDTO selectedStore = storeList.get(position - 1);
|
||||
loadStaff(selectedStore.getId());
|
||||
if (!isPastAppointment) {
|
||||
UIUtils.setViewsEnabled(true, binding.spinnerStaff);
|
||||
}
|
||||
} else {
|
||||
staffList.clear();
|
||||
refreshStaffSpinner();
|
||||
if (!isEditing) {
|
||||
binding.spinnerStaff.setSelection(0);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerStaff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,19 +308,8 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
binding.tvAppointmentId.setVisibility(View.VISIBLE);
|
||||
binding.btnDeleteAppointment.setVisibility(View.VISIBLE);
|
||||
|
||||
binding.spinnerCustomer.setEnabled(false);
|
||||
binding.spinnerStore.setEnabled(false);
|
||||
binding.spinnerPet.setEnabled(false);
|
||||
binding.spinnerService.setEnabled(false);
|
||||
binding.spinnerCustomer.setAlpha(0.5f);
|
||||
binding.spinnerStore.setAlpha(0.5f);
|
||||
binding.spinnerPet.setAlpha(0.5f);
|
||||
binding.spinnerService.setAlpha(0.5f);
|
||||
|
||||
binding.tvLabelCustomer.setAlpha(0.5f);
|
||||
binding.tvLabelStore.setAlpha(0.5f);
|
||||
binding.tvLabelPet.setAlpha(0.5f);
|
||||
binding.tvLabelService.setAlpha(0.5f);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerCustomer, binding.spinnerStore, binding.spinnerPet, binding.spinnerService);
|
||||
UIUtils.setViewsAlpha(0.5f, binding.tvLabelCustomer, binding.tvLabelStore, binding.tvLabelPet, binding.tvLabelService);
|
||||
|
||||
loadAppointmentData();
|
||||
} else {
|
||||
@@ -324,19 +318,9 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
binding.btnDeleteAppointment.setVisibility(View.GONE);
|
||||
binding.tvAppointmentId.setVisibility(View.GONE);
|
||||
|
||||
binding.spinnerCustomer.setEnabled(true);
|
||||
binding.spinnerStore.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.spinnerService.setAlpha(1.0f);
|
||||
|
||||
binding.tvLabelCustomer.setAlpha(1.0f);
|
||||
binding.tvLabelStore.setAlpha(1.0f);
|
||||
binding.tvLabelPet.setAlpha(1.0f);
|
||||
binding.tvLabelService.setAlpha(1.0f);
|
||||
UIUtils.setViewsEnabled(true, binding.spinnerCustomer, binding.spinnerStore, binding.spinnerService);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerPet, binding.spinnerStaff);
|
||||
UIUtils.setViewsAlpha(1.0f, binding.tvLabelCustomer, binding.tvLabelStore, binding.tvLabelPet, binding.tvLabelService, binding.tvLabelStaff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,8 +400,7 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
if ("Cancelled".equalsIgnoreCase(currentStatus)) {
|
||||
isPastAppointment = true;
|
||||
disableAllExceptStatus();
|
||||
binding.spinnerAppointmentStatus.setEnabled(false);
|
||||
binding.spinnerAppointmentStatus.setAlpha(0.5f);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerAppointmentStatus);
|
||||
binding.btnSaveAppointment.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
@@ -445,36 +428,18 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
* Disables all input fields except the status spinner
|
||||
*/
|
||||
private void disableAllExceptStatus() {
|
||||
binding.spinnerCustomer.setEnabled(false);
|
||||
binding.spinnerStore.setEnabled(false);
|
||||
binding.spinnerPet.setEnabled(false);
|
||||
binding.spinnerService.setEnabled(false);
|
||||
binding.spinnerStaff.setEnabled(false);
|
||||
binding.etAppointmentDate.setEnabled(false);
|
||||
binding.spinnerHour.setEnabled(false);
|
||||
binding.spinnerMinute.setEnabled(false);
|
||||
|
||||
float disabledAlpha = 0.5f;
|
||||
binding.spinnerCustomer.setAlpha(disabledAlpha);
|
||||
binding.spinnerStore.setAlpha(disabledAlpha);
|
||||
binding.spinnerPet.setAlpha(disabledAlpha);
|
||||
binding.spinnerService.setAlpha(disabledAlpha);
|
||||
binding.spinnerStaff.setAlpha(disabledAlpha);
|
||||
binding.etAppointmentDate.setAlpha(disabledAlpha);
|
||||
binding.spinnerHour.setAlpha(disabledAlpha);
|
||||
binding.spinnerMinute.setAlpha(disabledAlpha);
|
||||
|
||||
binding.tvLabelCustomer.setAlpha(disabledAlpha);
|
||||
binding.tvLabelStore.setAlpha(disabledAlpha);
|
||||
binding.tvLabelPet.setAlpha(disabledAlpha);
|
||||
binding.tvLabelService.setAlpha(disabledAlpha);
|
||||
binding.tvLabelStaff.setAlpha(disabledAlpha);
|
||||
binding.tvLabelDate.setAlpha(disabledAlpha);
|
||||
binding.tvLabelTime.setAlpha(disabledAlpha);
|
||||
UIUtils.setViewsEnabled(false,
|
||||
binding.spinnerCustomer, binding.spinnerStore, binding.spinnerPet,
|
||||
binding.spinnerService, binding.spinnerStaff, binding.etAppointmentDate,
|
||||
binding.spinnerHour, binding.spinnerMinute);
|
||||
|
||||
UIUtils.setViewsAlpha(0.5f,
|
||||
binding.tvLabelCustomer, binding.tvLabelStore, binding.tvLabelPet,
|
||||
binding.tvLabelService, binding.tvLabelStaff, binding.tvLabelDate,
|
||||
binding.tvLabelTime);
|
||||
|
||||
// Keep status enabled
|
||||
binding.spinnerAppointmentStatus.setEnabled(true);
|
||||
binding.spinnerAppointmentStatus.setAlpha(1.0f);
|
||||
UIUtils.setViewsEnabled(true, binding.spinnerAppointmentStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.example.petstoremobile.utils.DialogUtils;
|
||||
import com.example.petstoremobile.utils.InputValidator;
|
||||
import com.example.petstoremobile.utils.Resource;
|
||||
import com.example.petstoremobile.utils.SpinnerUtils;
|
||||
import com.example.petstoremobile.utils.UIUtils;
|
||||
import com.example.petstoremobile.viewmodels.CustomerViewModel;
|
||||
import com.example.petstoremobile.viewmodels.PetViewModel;
|
||||
import com.example.petstoremobile.viewmodels.StoreViewModel;
|
||||
@@ -221,10 +222,7 @@ public class PetDetailFragment extends Fragment {
|
||||
binding.btnDeletePet.setVisibility(View.VISIBLE);
|
||||
|
||||
// Disable species and breed fields in edit mode
|
||||
binding.etPetSpecies.setEnabled(false);
|
||||
binding.etPetBreed.setEnabled(false);
|
||||
binding.etPetSpecies.setAlpha(0.5f);
|
||||
binding.etPetBreed.setAlpha(0.5f);
|
||||
UIUtils.setViewsEnabled(false, binding.etPetSpecies, binding.etPetBreed);
|
||||
|
||||
loadPetData();
|
||||
} else {
|
||||
@@ -237,10 +235,7 @@ public class PetDetailFragment extends Fragment {
|
||||
binding.btnSavePet.setText("Add");
|
||||
|
||||
// Enable species and breed fields in edit mode
|
||||
binding.etPetSpecies.setEnabled(true);
|
||||
binding.etPetBreed.setEnabled(true);
|
||||
binding.etPetSpecies.setAlpha(1.0f);
|
||||
binding.etPetBreed.setAlpha(1.0f);
|
||||
UIUtils.setViewsEnabled(true, binding.etPetSpecies, binding.etPetBreed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,21 +340,17 @@ public class PetDetailFragment extends Fragment {
|
||||
//Disable the customer spinner if the status is "Available"
|
||||
if ("Available".equalsIgnoreCase(status)) {
|
||||
binding.spinnerCustomer.setSelection(0);
|
||||
binding.spinnerCustomer.setEnabled(false);
|
||||
binding.spinnerCustomer.setAlpha(0.5f);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerCustomer);
|
||||
} else {
|
||||
binding.spinnerCustomer.setEnabled(true);
|
||||
binding.spinnerCustomer.setAlpha(1.0f);
|
||||
UIUtils.setViewsEnabled(true, binding.spinnerCustomer);
|
||||
}
|
||||
|
||||
//Disable the store spinner if the status is "Owned"
|
||||
if ("Owned".equalsIgnoreCase(status)) {
|
||||
binding.spinnerStore.setSelection(0);
|
||||
binding.spinnerStore.setEnabled(false);
|
||||
binding.spinnerStore.setAlpha(0.5f);
|
||||
UIUtils.setViewsEnabled(false, binding.spinnerStore);
|
||||
} else {
|
||||
binding.spinnerStore.setEnabled(true);
|
||||
binding.spinnerStore.setAlpha(1.0f);
|
||||
UIUtils.setViewsEnabled(true, binding.spinnerStore);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,4 +369,4 @@ public class PetDetailFragment extends Fragment {
|
||||
((TextView) selectedView).setError(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.example.petstoremobile.viewmodels.*;
|
||||
import com.example.petstoremobile.utils.SpinnerUtils;
|
||||
import com.example.petstoremobile.utils.DialogUtils;
|
||||
import com.example.petstoremobile.utils.Resource;
|
||||
import com.example.petstoremobile.utils.UIUtils;
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
@@ -80,9 +81,10 @@ public class SaleDetailFragment extends Fragment {
|
||||
// Hide save and input controls for view only
|
||||
if (viewOnly) {
|
||||
binding.btnSaveSale.setVisibility(View.GONE);
|
||||
binding.spinnerSaleStore.setEnabled(false);
|
||||
binding.spinnerSaleCustomer.setEnabled(false);
|
||||
binding.spinnerPaymentMethod.setEnabled(false);
|
||||
UIUtils.setViewsEnabled(false,
|
||||
binding.spinnerSaleStore,
|
||||
binding.spinnerSaleCustomer,
|
||||
binding.spinnerPaymentMethod);
|
||||
binding.llAddItemRow.setVisibility(View.GONE);
|
||||
binding.llExtraInfo.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@@ -66,4 +66,28 @@ public class UIUtils {
|
||||
@Override public void afterTextChanged(Editable s) {}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled state and alpha for multiple views.
|
||||
* Alpha is set to 1.0f when enabled and 0.5f when disabled.
|
||||
*/
|
||||
public static void setViewsEnabled(boolean enabled, View... views) {
|
||||
for (View v : views) {
|
||||
if (v != null) {
|
||||
v.setEnabled(enabled);
|
||||
v.setAlpha(enabled ? 1.0f : 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the alpha for multiple views.
|
||||
*/
|
||||
public static void setViewsAlpha(float alpha, View... views) {
|
||||
for (View v : views) {
|
||||
if (v != null) {
|
||||
v.setAlpha(alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user