Skip to content

Commit cbe930b

Browse files
committed
added total costs in grouped objects
1 parent 216ac6f commit cbe930b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

app/src/main/java/com/georgemc2610/benzinapp/fragments/history/HistoryFragment.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,22 @@ private void createCards()
108108
List<FuelFillRecord> recordsInMonthYear = groupedRecords.get(key);
109109
String stringYearMonth = key.format(formatter);
110110

111+
TextView totalCostLegend = null;
112+
float totalCost = 0f;
113+
111114
for (FuelFillRecord record : recordsInMonthYear)
112115
{
116+
// add total cost count
117+
totalCost += record.getCost_eur();
118+
113119
// inflate the card view for the fuel fill records.
114120
View v;
115121

116122
if (recordsInMonthYear.indexOf(record) == 0)
117123
{
118124
v = inflater.inflate(R.layout.cardview_fill_with_legend, null);
119125
TextView legend = v.findViewById(R.id.card_year_month_legend);
126+
totalCostLegend = v.findViewById(R.id.card_cost_legend);
120127
legend.setText(stringYearMonth);
121128
}
122129
else
@@ -186,6 +193,13 @@ private void createCards()
186193
// change the hint text.
187194
hint.setText(getString(R.string.text_view_click_cards_message));
188195
}
196+
197+
if (totalCostLegend != null)
198+
{
199+
DecimalFormat decimalFormat = new DecimalFormat("#.##");
200+
String totalCostString = "€" + decimalFormat.format(totalCost);
201+
totalCostLegend.setText(totalCostString);
202+
}
189203
}
190204
}
191205

app/src/main/res/layout/cardview_fill_with_legend.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,23 @@
1313
android:layout_marginStart="7dp"
1414
android:layout_marginTop="8dp"
1515
android:layout_marginEnd="7dp"
16-
android:layout_marginBottom="8dp"
16+
android:layout_marginBottom="2dp"
1717
android:text="mmmm YYYY"
1818
style="@style/textColor"
1919
android:textSize="24sp"
2020
android:textStyle="bold"/>
2121

22+
<TextView
23+
android:id="@+id/card_cost_legend"
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:layout_marginStart="7dp"
27+
android:layout_marginEnd="7dp"
28+
android:layout_marginBottom="8dp"
29+
android:text="total cost"
30+
style="@style/textColorSpecial"
31+
android:textSize="12sp"/>
32+
2233
<androidx.cardview.widget.CardView
2334
android:layout_width="match_parent"
2435
android:layout_height="105dp"

0 commit comments

Comments
 (0)