Open flauschtrud opened 3 years ago
Initial fix idea unfortunately breaks seasonal search:
private void setUpSpinner() {
ArrayAdapter<Category> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item);
arrayAdapter.add(Category.ALL);
arrayAdapter.add(Category.SEASONAL);
arrayAdapter.add(Category.UNASSIGNED);
arrayAdapter.add(Category.FAVORITES);
viewModel.getCategories().observe(getViewLifecycleOwner(), categories -> categories.forEach(arrayAdapter::add));
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(arrayAdapter);
spinner.post(() -> {
spinner.setOnItemSelectedListener(this);
Category selectedCategory = viewModel.getCategory() != null? viewModel.getCategory() : getPreferredCategory();
int position = arrayAdapter.getPosition(selectedCategory);
spinner.setSelection(position, false);
viewModel.setFilterName(selectedCategory.getName());
});
}
(only applies to custom categories)