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));
}
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 -> {
});
}
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;
}
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()));
}
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);
}
Aggregations