use of xyz.zedler.patrick.grocy.fragment.ShoppingListFragment 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;
}
use of xyz.zedler.patrick.grocy.fragment.ShoppingListFragment in project grocy-android by patzly.
the class DrawerBottomSheet method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentBottomsheetDrawerBinding.inflate(inflater, container, false);
activity = (MainActivity) requireActivity();
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
binding.buttonDrawerShoppingMode.setOnClickListener(v -> navigateDeepLink(R.string.deep_link_shoppingModeFragment));
ClickUtil.setOnClickListeners(this, binding.linearDrawerStock, binding.linearDrawerShoppingList, binding.linearDrawerConsume, binding.linearDrawerPurchase, binding.linearDrawerTransfer, binding.linearDrawerInventory, binding.linearDrawerMasterData, binding.linearDrawerSettings, binding.linearDrawerFeedback, binding.linearDrawerHelp);
BaseFragment currentFragment = activity.getCurrentFragment();
if (currentFragment instanceof StockOverviewFragment) {
select(binding.linearDrawerStock, binding.textDrawerStock, false);
} else if (currentFragment instanceof ShoppingListFragment) {
select(binding.linearDrawerShoppingList, binding.textDrawerShoppingList, false);
} else if (currentFragment instanceof ConsumeFragment) {
select(binding.linearDrawerConsume, null, true);
} else if (currentFragment instanceof PurchaseFragment) {
select(binding.linearDrawerPurchase, null, true);
} else if (currentFragment instanceof TransferFragment) {
select(binding.linearDrawerTransfer, null, true);
} else if (currentFragment instanceof InventoryFragment) {
select(binding.linearDrawerInventory, null, true);
} else if (currentFragment instanceof MasterObjectListFragment) {
select(binding.linearDrawerMasterData, binding.textDrawerMasterData, false);
} else if (currentFragment instanceof SettingsFragment) {
select(binding.linearDrawerSettings, binding.textDrawerSettings, false);
}
hideDisabledFeatures();
return binding.getRoot();
}
Aggregations