Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 728918a

Browse files
author
Evgeniy Kanivets
committed
Added totals fields to report
1 parent cc560b1 commit 728918a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/adapter/RecordAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {
7474
tvTime.setText(dateFormat.format(new Date(records.get(position).getTime())));
7575

7676
tvPrice.setText((records.get(position).isIncome() ? "+ " : "- ")
77-
+ Integer.toString(records.get(position).getPrice()));
77+
+ "$" + Integer.toString(records.get(position).getPrice()));
7878
tvTitle.setText(records.get(position).getTitle());
7979
tvCategory.setText(records.get(position).getCategory());
8080

app/src/main/java/com/blogspot/e_kanivets/moneytracker/model/Report.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,26 @@ private void makeReport() {
4545
}
4646

4747
// Calculate total of all records
48-
int total = 0;
48+
int totalIncome = 0, totalExpense = 0;
4949

5050
//Convert HashMap to ArrayList
5151
reportList = new ArrayList<Pair<String, Integer>>();
5252
for(String name : map.keySet()) {
5353
reportList.add(new Pair<String, Integer>(name, map.get(name)));
54-
total += map.get(name);
54+
if(map.get(name) > 0) {
55+
totalIncome += map.get(name);
56+
}
57+
else {
58+
totalExpense += map.get(name);
59+
}
5560
}
5661

5762
//Add summary row to list
5863
reportList.add(new Pair<String, Integer>(
59-
MTApp.get().getResources().getString(R.string.total) + " :", total));
64+
MTApp.get().getResources().getString(R.string.total_incomes) + " :", totalIncome));
65+
reportList.add(new Pair<String, Integer>(
66+
MTApp.get().getResources().getString(R.string.total_expenses) + " :", totalExpense));
67+
reportList.add(new Pair<String, Integer>(
68+
MTApp.get().getResources().getString(R.string.total) + " :", totalExpense + totalIncome));
6069
}
6170
}

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<string name="report">Report</string>
2121
<string name="change_date">CHANGE THE DATE</string>
2222
<string name="total">TOTAL</string>
23+
<string name="total_incomes">Total incomes</string>
24+
<string name="total_expenses">Total expenses</string>
2325
<string name="edit">Edit</string>
2426
<string name="delete">Delete</string>
2527
<string name="save">Save</string>

0 commit comments

Comments
 (0)