use of xyz.zedler.patrick.grocy.model.ShoppingList in project grocy-android by patzly.
the class ShoppingListAdapter method onBindViewHolder.
@SuppressLint("ClickableViewAccessibility")
@Override
public void onBindViewHolder(@NonNull final ShoppingListAdapter.ViewHolder holder, int position) {
ShoppingList shoppingList = shoppingLists.get(holder.getAdapterPosition());
holder.name.setText(shoppingList.getName());
if (shoppingList.getId() == selectedId) {
holder.imageSelected.setVisibility(View.VISIBLE);
}
holder.container.setOnClickListener(view -> listener.onItemRowClicked(shoppingList));
if (shoppingList.getId() == 1) {
holder.delete.setVisibility(View.GONE);
}
holder.delete.setOnTouchListener((v, event) -> {
listener.onTouchDelete(v, event, shoppingList);
return true;
});
holder.edit.setOnClickListener(v -> listener.onClickEdit(shoppingList));
if (!showActions) {
holder.delete.setVisibility(View.GONE);
holder.edit.setVisibility(View.GONE);
}
}
use of xyz.zedler.patrick.grocy.model.ShoppingList in project grocy-android by patzly.
the class ShoppingListFragment method changeAppBarTitle.
private void changeAppBarTitle(int selectedShoppingListId) {
ShoppingList shoppingList = viewModel.getShoppingListFromId(selectedShoppingListId);
if (shoppingList == null) {
return;
}
ShoppingListHelper.changeAppBarTitle(binding.textShoppingListTitle, binding.buttonShoppingListLists, shoppingList);
}
use of xyz.zedler.patrick.grocy.model.ShoppingList in project grocy-android by patzly.
the class ShoppingListFragment method setUpBottomMenu.
public void setUpBottomMenu() {
if (activity == null) {
// Fixes crash on theme change
return;
}
MenuItem search = activity.getBottomMenu().findItem(R.id.action_search);
if (search != null) {
search.setOnMenuItemClickListener(item -> {
ViewUtil.startIcon(item);
setUpSearch();
return true;
});
}
MenuItem shoppingMode = activity.getBottomMenu().findItem(R.id.action_shopping_mode);
if (shoppingMode != null) {
shoppingMode.setOnMenuItemClickListener(item -> {
navigate(ShoppingListFragmentDirections.actionShoppingListFragmentToShoppingModeFragment());
return true;
});
}
MenuItem addMissing = activity.getBottomMenu().findItem(R.id.action_add_missing);
if (addMissing != null) {
addMissing.setOnMenuItemClickListener(item -> {
ViewUtil.startIcon(item);
viewModel.addMissingItems();
return true;
});
}
MenuItem purchaseAllItems = activity.getBottomMenu().findItem(R.id.action_purchase_all_items);
if (purchaseAllItems != null) {
purchaseAllItems.setOnMenuItemClickListener(item -> {
ArrayList<ShoppingListItem> shoppingListItemsSelected = viewModel.getFilteredShoppingListItemsLive().getValue();
if (shoppingListItemsSelected == null) {
showMessage(activity.getString(R.string.error_undefined));
return true;
}
if (shoppingListItemsSelected.isEmpty()) {
showMessage(activity.getString(R.string.error_empty_shopping_list));
return true;
}
ArrayList<ShoppingListItem> listItems = new ArrayList<>(shoppingListItemsSelected);
HashMap<Integer, String> productNamesHashMap = viewModel.getProductNamesHashMap();
if (productNamesHashMap == null) {
showMessage(activity.getString(R.string.error_undefined));
return true;
}
SortUtil.sortShoppingListItemsByName(requireContext(), listItems, productNamesHashMap, true);
int[] array = new int[listItems.size()];
for (int i = 0; i < array.length; i++) {
array[i] = listItems.get(i).getId();
}
navigate(R.id.purchaseFragment, new PurchaseFragmentArgs.Builder().setShoppingListItems(array).setCloseWhenFinished(true).build().toBundle());
return true;
});
}
MenuItem purchaseDoneItems = activity.getBottomMenu().findItem(R.id.action_purchase_done_items);
if (purchaseDoneItems != null) {
purchaseDoneItems.setOnMenuItemClickListener(item -> {
ArrayList<ShoppingListItem> shoppingListItemsSelected = viewModel.getFilteredShoppingListItemsLive().getValue();
if (shoppingListItemsSelected == null) {
showMessage(activity.getString(R.string.error_undefined));
return true;
}
if (shoppingListItemsSelected.isEmpty()) {
showMessage(activity.getString(R.string.error_empty_shopping_list));
return true;
}
ArrayList<ShoppingListItem> listItems = new ArrayList<>(shoppingListItemsSelected);
HashMap<Integer, String> productNamesHashMap = viewModel.getProductNamesHashMap();
if (productNamesHashMap == null) {
showMessage(activity.getString(R.string.error_undefined));
return true;
}
ArrayList<ShoppingListItem> doneItems = new ArrayList<>();
for (ShoppingListItem tempItem : listItems) {
if (!tempItem.isUndone())
doneItems.add(tempItem);
}
if (doneItems.isEmpty()) {
showMessage(activity.getString(R.string.error_no_done_items));
return true;
}
SortUtil.sortShoppingListItemsByName(requireContext(), doneItems, productNamesHashMap, true);
int[] array = new int[doneItems.size()];
for (int i = 0; i < array.length; i++) {
array[i] = doneItems.get(i).getId();
}
navigate(R.id.purchaseFragment, new PurchaseFragmentArgs.Builder().setShoppingListItems(array).setCloseWhenFinished(true).build().toBundle());
return true;
});
}
MenuItem editNotes = activity.getBottomMenu().findItem(R.id.action_edit_notes);
if (editNotes != null) {
editNotes.setOnMenuItemClickListener(item -> {
showNotesEditor();
return true;
});
}
MenuItem clear = activity.getBottomMenu().findItem(R.id.action_clear);
if (clear != null) {
clear.setOnMenuItemClickListener(item -> {
ViewUtil.startIcon(item);
ShoppingList shoppingList = viewModel.getSelectedShoppingList();
if (shoppingList == null) {
showMessage(activity.getString(R.string.error_undefined));
return true;
}
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.ARGUMENT.SHOPPING_LIST, shoppingList);
activity.showBottomSheet(new ShoppingListClearBottomSheet(), bundle);
return true;
});
}
}
use of xyz.zedler.patrick.grocy.model.ShoppingList in project grocy-android by patzly.
the class ShoppingModeFragment method showNotesEditor.
private void showNotesEditor() {
Bundle bundle = new Bundle();
bundle.putString(Constants.ARGUMENT.TITLE, activity.getString(R.string.action_edit_notes));
bundle.putString(Constants.ARGUMENT.HINT, activity.getString(R.string.property_notes));
ShoppingList shoppingList = viewModel.getSelectedShoppingList();
if (shoppingList == null) {
return;
}
bundle.putString(Constants.ARGUMENT.HTML, shoppingList.getNotes());
activity.showBottomSheet(new TextEditBottomSheet(), bundle);
}
use of xyz.zedler.patrick.grocy.model.ShoppingList in project grocy-android by patzly.
the class ShoppingModeFragment method changeAppBarTitle.
private void changeAppBarTitle(int selectedShoppingListId) {
ShoppingList shoppingList = viewModel.getShoppingListFromId(selectedShoppingListId);
if (shoppingList == null) {
return;
}
ShoppingListHelper.changeAppBarTitle(binding.textShoppingListTitle, binding.buttonShoppingListLists, shoppingList);
}
Aggregations