use of xyz.zedler.patrick.grocy.model.PriceHistoryEntry 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 -> {
});
}
Aggregations