Search in sources :

Example 1 with ShoppingList

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);
    }
}
Also used : ShoppingList(xyz.zedler.patrick.grocy.model.ShoppingList) SuppressLint(android.annotation.SuppressLint)

Example 2 with ShoppingList

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);
}
Also used : ShoppingList(xyz.zedler.patrick.grocy.model.ShoppingList)

Example 3 with 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;
        });
    }
}
Also used : ShoppingList(xyz.zedler.patrick.grocy.model.ShoppingList) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) ShoppingListItem(xyz.zedler.patrick.grocy.model.ShoppingListItem) ShoppingListClearBottomSheet(xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.ShoppingListClearBottomSheet)

Example 4 with ShoppingList

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);
}
Also used : Bundle(android.os.Bundle) ShoppingList(xyz.zedler.patrick.grocy.model.ShoppingList) TextEditBottomSheet(xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.TextEditBottomSheet)

Example 5 with ShoppingList

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);
}
Also used : ShoppingList(xyz.zedler.patrick.grocy.model.ShoppingList)

Aggregations

ShoppingList (xyz.zedler.patrick.grocy.model.ShoppingList)15 ArrayList (java.util.ArrayList)5 ShoppingListItem (xyz.zedler.patrick.grocy.model.ShoppingListItem)5 Bundle (android.os.Bundle)4 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 TextEditBottomSheet (xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.TextEditBottomSheet)2 Product (xyz.zedler.patrick.grocy.model.Product)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 Animatable (android.graphics.drawable.Animatable)1 Spanned (android.text.Spanned)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 MotionEvent (android.view.MotionEvent)1