Search in sources :

Example 1 with Store

use of xyz.zedler.patrick.grocy.model.Store in project grocy-android by patzly.

the class ProductBarcodeAdapter method onBindViewHolder.

@SuppressLint("ClickableViewAccessibility")
@Override
public void onBindViewHolder(@NonNull final ProductBarcodeAdapter.ViewHolder holder, int position) {
    ProductBarcode productBarcode = productBarcodes.get(holder.getAdapterPosition());
    holder.binding.barcode.setText(productBarcode.getBarcode());
    if (NumUtil.isStringDouble(productBarcode.getAmount())) {
        String amountStr = holder.binding.amount.getContext().getString(R.string.subtitle_barcode_amount, NumUtil.trim(Double.parseDouble(productBarcode.getAmount())));
        holder.binding.amount.setText(amountStr);
        holder.binding.amount.setVisibility(View.VISIBLE);
    } else {
        holder.binding.amount.setVisibility(View.GONE);
    }
    if (productBarcode.getNote() != null && !productBarcode.getNote().trim().isEmpty()) {
        holder.binding.note.setText(productBarcode.getNote());
        holder.binding.note.setVisibility(View.VISIBLE);
    } else {
        holder.binding.note.setVisibility(View.GONE);
    }
    if (productBarcode.getQuIdInt() != -1) {
        for (QuantityUnit qU : quantityUnits) {
            if (qU.getId() == productBarcode.getQuIdInt()) {
                String qUnitStr = holder.binding.amount.getContext().getString(R.string.subtitle_barcode_unit, qU.getName());
                holder.binding.quantityUnit.setText(qUnitStr);
                holder.binding.quantityUnit.setVisibility(View.VISIBLE);
            }
        }
    } else {
        holder.binding.quantityUnit.setVisibility(View.GONE);
    }
    if (productBarcode.getStoreIdInt() != -1) {
        for (Store store : stores) {
            if (store.getId() == productBarcode.getStoreIdInt()) {
                // TODO create dedicated string
                String storeStr = holder.binding.store.getContext().getString(R.string.property_store) + ": " + store.getName();
                holder.binding.store.setText(storeStr);
                holder.binding.store.setVisibility(View.VISIBLE);
            }
        }
    } else {
        holder.binding.store.setVisibility(View.GONE);
    }
    holder.binding.container.setOnClickListener(view -> listener.onItemRowClicked(productBarcode));
}
Also used : Store(xyz.zedler.patrick.grocy.model.Store) ProductBarcode(xyz.zedler.patrick.grocy.model.ProductBarcode) QuantityUnit(xyz.zedler.patrick.grocy.model.QuantityUnit) SuppressLint(android.annotation.SuppressLint)

Example 2 with Store

use of xyz.zedler.patrick.grocy.model.Store in project grocy-android by patzly.

the class ProductOverviewBottomSheet method loadPriceHistory.

private void loadPriceHistory() {
    if (!isFeatureEnabled(Constants.PREF.FEATURE_STOCK_PRICE_TRACKING)) {
        return;
    }
    dlHelper.get(activity.getGrocyApi().getPriceHistory(product.getId()), response -> {
        Type listType = new TypeToken<ArrayList<PriceHistoryEntry>>() {
        }.getType();
        ArrayList<PriceHistoryEntry> priceHistoryEntries;
        priceHistoryEntries = new Gson().fromJson(response, listType);
        if (priceHistoryEntries.isEmpty()) {
            return;
        }
        ArrayList<String> dates = new ArrayList<>();
        Collections.reverse(priceHistoryEntries);
        HashMap<String, ArrayList<BezierCurveChart.Point>> curveLists = new HashMap<>();
        for (PriceHistoryEntry priceHistoryEntry : priceHistoryEntries) {
            Store store = priceHistoryEntry.getStore();
            String storeName;
            if (store == null || store.getName().trim().isEmpty()) {
                storeName = activity.getString(R.string.property_store_unknown);
            } else {
                storeName = store.getName().trim();
            }
            if (!curveLists.containsKey(storeName)) {
                curveLists.put(storeName, new ArrayList<>());
            }
            ArrayList<BezierCurveChart.Point> curveList = curveLists.get(storeName);
            String date = new DateUtil(activity).getLocalizedDate(priceHistoryEntry.getDate(), DateUtil.FORMAT_SHORT);
            if (!dates.contains(date)) {
                dates.add(date);
            }
            assert curveList != null;
            curveList.add(new BezierCurveChart.Point(dates.indexOf(date), (float) priceHistoryEntry.getPrice()));
        }
        binding.itemPriceHistory.init(curveLists, dates);
        animateLinearPriceHistory();
    }, error -> {
    });
}
Also used : PriceHistoryEntry(xyz.zedler.patrick.grocy.model.PriceHistoryEntry) HashMap(java.util.HashMap) BezierCurveChart(xyz.zedler.patrick.grocy.view.BezierCurveChart) DateUtil(xyz.zedler.patrick.grocy.util.DateUtil) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Store(xyz.zedler.patrick.grocy.model.Store) Type(java.lang.reflect.Type)

Example 3 with Store

use of xyz.zedler.patrick.grocy.model.Store in project grocy-android by patzly.

the class ShoppingListItemAdapter method getGroupedListItems.

static ArrayList<GroupedListItem> getGroupedListItems(Context context, ArrayList<ShoppingListItem> shoppingListItems, HashMap<Integer, ProductGroup> productGroupHashMap, HashMap<Integer, Product> productHashMap, HashMap<Integer, String> productNamesHashMap, HashMap<Integer, Store> storeHashMap, String shoppingListNotes, String groupingMode) {
    if (groupingMode.equals(FilterChipLiveDataShoppingListGrouping.GROUPING_NONE)) {
        SortUtil.sortShoppingListItemsByName(context, shoppingListItems, productNamesHashMap, true);
        ArrayList<GroupedListItem> groupedListItems = new ArrayList<>(shoppingListItems);
        addBottomNotes(context, shoppingListNotes, groupedListItems, !shoppingListItems.isEmpty());
        return groupedListItems;
    }
    HashMap<String, ArrayList<ShoppingListItem>> shoppingListItemsGroupedHashMap = new HashMap<>();
    ArrayList<ShoppingListItem> ungroupedItems = new ArrayList<>();
    for (ShoppingListItem shoppingListItem : shoppingListItems) {
        String groupName = null;
        if (groupingMode.equals(FilterChipLiveDataShoppingListGrouping.GROUPING_PRODUCT_GROUP) && shoppingListItem.hasProduct()) {
            Product product = productHashMap.get(shoppingListItem.getProductIdInt());
            Integer productGroupId = product != null && NumUtil.isStringInt(product.getProductGroupId()) ? Integer.parseInt(product.getProductGroupId()) : null;
            ProductGroup productGroup = productGroupId != null ? productGroupHashMap.get(productGroupId) : null;
            groupName = productGroup != null ? productGroup.getName() : null;
        } else if (groupingMode.equals(FilterChipLiveDataShoppingListGrouping.GROUPING_STORE) && shoppingListItem.hasProduct()) {
            Product product = productHashMap.get(shoppingListItem.getProductIdInt());
            Integer storeId = product != null && NumUtil.isStringInt(product.getStoreId()) ? Integer.parseInt(product.getStoreId()) : null;
            Store store = storeId != null ? storeHashMap.get(storeId) : null;
            groupName = store != null ? store.getName() : null;
        }
        if (groupName != null && !groupName.isEmpty()) {
            ArrayList<ShoppingListItem> itemsFromGroup = shoppingListItemsGroupedHashMap.get(groupName);
            if (itemsFromGroup == null) {
                itemsFromGroup = new ArrayList<>();
                shoppingListItemsGroupedHashMap.put(groupName, itemsFromGroup);
            }
            itemsFromGroup.add(shoppingListItem);
        } else {
            ungroupedItems.add(shoppingListItem);
        }
    }
    ArrayList<GroupedListItem> groupedListItems = new ArrayList<>();
    ArrayList<String> groupsSorted = new ArrayList<>(shoppingListItemsGroupedHashMap.keySet());
    SortUtil.sortStringsByName(context, groupsSorted, true);
    if (!ungroupedItems.isEmpty()) {
        groupedListItems.add(new GroupHeader(context.getString(R.string.property_ungrouped)));
        SortUtil.sortShoppingListItemsByName(context, ungroupedItems, productNamesHashMap, true);
        groupedListItems.addAll(ungroupedItems);
    }
    for (String group : groupsSorted) {
        ArrayList<ShoppingListItem> itemsFromGroup = shoppingListItemsGroupedHashMap.get(group);
        if (itemsFromGroup == null)
            continue;
        GroupHeader groupHeader = new GroupHeader(group);
        groupHeader.setDisplayDivider(!ungroupedItems.isEmpty() || !groupsSorted.get(0).equals(group));
        groupedListItems.add(groupHeader);
        SortUtil.sortShoppingListItemsByName(context, itemsFromGroup, productNamesHashMap, true);
        groupedListItems.addAll(itemsFromGroup);
    }
    addBottomNotes(context, shoppingListNotes, groupedListItems, !ungroupedItems.isEmpty() || !groupsSorted.isEmpty());
    return groupedListItems;
}
Also used : ProductGroup(xyz.zedler.patrick.grocy.model.ProductGroup) GroupedListItem(xyz.zedler.patrick.grocy.model.GroupedListItem) HashMap(java.util.HashMap) GroupHeader(xyz.zedler.patrick.grocy.model.GroupHeader) ArrayList(java.util.ArrayList) Product(xyz.zedler.patrick.grocy.model.Product) Store(xyz.zedler.patrick.grocy.model.Store) ShoppingListItem(xyz.zedler.patrick.grocy.model.ShoppingListItem)

Example 4 with Store

use of xyz.zedler.patrick.grocy.model.Store in project grocy-android by patzly.

the class StoreAdapter method onBindViewHolder.

@SuppressLint("ClickableViewAccessibility")
@Override
public void onBindViewHolder(@NonNull final StoreAdapter.ViewHolder holder, int position) {
    Store store = stores.get(holder.getAdapterPosition());
    // NAME
    holder.textViewName.setText(store.getName());
    if (store.getId() == selectedId) {
        holder.imageViewSelected.setVisibility(View.VISIBLE);
    }
    // CONTAINER
    holder.linearLayoutContainer.setOnClickListener(view -> listener.onItemRowClicked(holder.getAdapterPosition()));
}
Also used : Store(xyz.zedler.patrick.grocy.model.Store) SuppressLint(android.annotation.SuppressLint)

Example 5 with Store

use of xyz.zedler.patrick.grocy.model.Store in project grocy-android by patzly.

the class MasterProductCatLocationFragment method showStoresBottomSheet.

public void showStoresBottomSheet() {
    ArrayList<Store> stores = viewModel.getFormData().getStoresLive().getValue();
    if (stores == null) {
        viewModel.showErrorMessage();
        return;
    }
    Bundle bundle = new Bundle();
    bundle.putParcelableArrayList(Constants.ARGUMENT.STORES, stores);
    bundle.putBoolean(ARGUMENT.DISPLAY_EMPTY_OPTION, true);
    Store store = viewModel.getFormData().getStoreLive().getValue();
    int storeId = store != null ? store.getId() : -1;
    bundle.putInt(Constants.ARGUMENT.SELECTED_ID, storeId);
    activity.showBottomSheet(new StoresBottomSheet(), bundle);
}
Also used : StoresBottomSheet(xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.StoresBottomSheet) Bundle(android.os.Bundle) Store(xyz.zedler.patrick.grocy.model.Store)

Aggregations

Store (xyz.zedler.patrick.grocy.model.Store)7 ArrayList (java.util.ArrayList)3 SuppressLint (android.annotation.SuppressLint)2 Bundle (android.os.Bundle)2 Gson (com.google.gson.Gson)2 Type (java.lang.reflect.Type)2 HashMap (java.util.HashMap)2 View (android.view.View)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 List (java.util.List)1 StoreAdapter (xyz.zedler.patrick.grocy.adapter.StoreAdapter)1 StoresBottomSheet (xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.StoresBottomSheet)1 GroupHeader (xyz.zedler.patrick.grocy.model.GroupHeader)1 GroupedListItem (xyz.zedler.patrick.grocy.model.GroupedListItem)1 PriceHistoryEntry (xyz.zedler.patrick.grocy.model.PriceHistoryEntry)1 Product (xyz.zedler.patrick.grocy.model.Product)1