diff --git a/app/src/main/java/com/georgemc2610/benzinapp/fragments/history/HistoryFragment.java b/app/src/main/java/com/georgemc2610/benzinapp/fragments/history/HistoryFragment.java index f881adcf..75756cd9 100644 --- a/app/src/main/java/com/georgemc2610/benzinapp/fragments/history/HistoryFragment.java +++ b/app/src/main/java/com/georgemc2610/benzinapp/fragments/history/HistoryFragment.java @@ -108,8 +108,14 @@ private void createCards() List recordsInMonthYear = groupedRecords.get(key); String stringYearMonth = key.format(formatter); + TextView totalCostLegend = null; + float totalCost = 0f; + for (FuelFillRecord record : recordsInMonthYear) { + // add total cost count + totalCost += record.getCost_eur(); + // inflate the card view for the fuel fill records. View v; @@ -117,6 +123,7 @@ private void createCards() { v = inflater.inflate(R.layout.cardview_fill_with_legend, null); TextView legend = v.findViewById(R.id.card_year_month_legend); + totalCostLegend = v.findViewById(R.id.card_cost_legend); legend.setText(stringYearMonth); } else @@ -186,6 +193,13 @@ private void createCards() // change the hint text. hint.setText(getString(R.string.text_view_click_cards_message)); } + + if (totalCostLegend != null) + { + DecimalFormat decimalFormat = new DecimalFormat("#.##"); + String totalCostString = "€" + decimalFormat.format(totalCost); + totalCostLegend.setText(totalCostString); + } } } diff --git a/app/src/main/res/layout/cardview_fill_with_legend.xml b/app/src/main/res/layout/cardview_fill_with_legend.xml index 938cf24d..50a00b63 100644 --- a/app/src/main/res/layout/cardview_fill_with_legend.xml +++ b/app/src/main/res/layout/cardview_fill_with_legend.xml @@ -13,12 +13,23 @@ android:layout_marginStart="7dp" android:layout_marginTop="8dp" android:layout_marginEnd="7dp" - android:layout_marginBottom="8dp" + android:layout_marginBottom="2dp" android:text="mmmm YYYY" style="@style/textColor" android:textSize="24sp" android:textStyle="bold"/> + +