Skip to content

Commit

Permalink
added total costs in grouped objects
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeMC2610 committed Mar 4, 2024
1 parent 216ac6f commit cbe930b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,22 @@ private void createCards()
List<FuelFillRecord> 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;

if (recordsInMonthYear.indexOf(record) == 0)
{
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
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/layout/cardview_fill_with_legend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

<TextView
android:id="@+id/card_cost_legend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
android:layout_marginBottom="8dp"
android:text="total cost"
style="@style/textColorSpecial"
android:textSize="12sp"/>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="105dp"
Expand Down

0 comments on commit cbe930b

Please sign in to comment.