use of xyz.zedler.patrick.grocy.adapter.ShoppingListAdapter in project grocy-android by patzly.
the class ShoppingListsBottomSheet method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_bottomsheet_list_selection, container, false);
activity = (MainActivity) requireActivity();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
boolean multipleListsFeature = sharedPrefs.getBoolean(Constants.PREF.FEATURE_MULTIPLE_SHOPPING_LISTS, true);
MutableLiveData<Integer> selectedIdLive = activity.getCurrentFragment().getSelectedShoppingListIdLive();
if (selectedIdLive == null) {
dismiss();
return view;
}
ShoppingListRepository repository = new ShoppingListRepository(activity.getApplication());
TextView textViewTitle = view.findViewById(R.id.text_list_selection_title);
textViewTitle.setText(activity.getString(R.string.property_shopping_lists));
RecyclerView recyclerView = view.findViewById(R.id.recycler_list_selection);
recyclerView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(new ShoppingPlaceholderAdapter());
repository.getShoppingListsLive().observe(getViewLifecycleOwner(), shoppingLists -> {
if (shoppingLists == null) {
return;
}
if (recyclerView.getAdapter() == null || !(recyclerView.getAdapter() instanceof ShoppingListAdapter)) {
recyclerView.setAdapter(new ShoppingListAdapter(shoppingLists, selectedIdLive.getValue(), this, activity.getCurrentFragment() instanceof ShoppingListFragment && activity.isOnline()));
} else {
((ShoppingListAdapter) recyclerView.getAdapter()).updateData(shoppingLists, selectedIdLive.getValue());
}
});
selectedIdLive.observe(getViewLifecycleOwner(), selectedId -> {
if (recyclerView.getAdapter() == null || !(recyclerView.getAdapter() instanceof ShoppingListAdapter)) {
return;
}
((ShoppingListAdapter) recyclerView.getAdapter()).updateSelectedId(selectedIdLive.getValue());
});
ActionButton buttonNew = view.findViewById(R.id.button_list_selection_new);
if (activity.isOnline() && multipleListsFeature && activity.getCurrentFragment() instanceof ShoppingListFragment) {
buttonNew.setVisibility(View.VISIBLE);
buttonNew.setOnClickListener(v -> {
dismiss();
navigate(ShoppingListFragmentDirections.actionShoppingListFragmentToShoppingListEditFragment());
});
}
progressConfirm = view.findViewById(R.id.progress_confirmation);
return view;
}
Aggregations