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

Commit 3d6afb0

Browse files
author
Evgeniy Kanivets
committed
Added report option(functionality and view)
1 parent 0babba3 commit 3d6afb0

File tree

7 files changed

+120
-3
lines changed

7 files changed

+120
-3
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<category android:name="android.intent.category.LAUNCHER" />
1919
</intent-filter>
2020
</activity>
21+
<activity android:name=".activity.ReportActivity"></activity>
2122
</application>
2223

2324
</manifest>

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/MainActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Activity;
44
import android.app.DatePickerDialog;
55
import android.content.DialogInterface;
6+
import android.content.Intent;
67
import android.content.pm.FeatureInfo;
78
import android.database.Cursor;
89
import android.database.sqlite.SQLiteDatabase;
@@ -125,6 +126,14 @@ public void OnDataChanged(Date date) {
125126
}
126127
});
127128

129+
btnReport.setOnClickListener(new View.OnClickListener() {
130+
@Override
131+
public void onClick(View view) {
132+
Intent intent = new Intent(MainActivity.this, ReportActivity.class);
133+
startActivity(intent);
134+
}
135+
});
136+
128137
listView.setAdapter(new RecordAdapter(activity, MTHelper.getInstance().getRecords()));
129138
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
130139

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.blogspot.e_kanivets.moneytracker.activity;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.widget.ListView;
6+
import android.widget.TextView;
7+
8+
import com.blogspot.e_kanivets.moneytracker.R;
9+
import com.blogspot.e_kanivets.moneytracker.helper.MTHelper;
10+
11+
/**
12+
* Created by eugene on 11/09/14.
13+
*/
14+
public class ReportActivity extends Activity {
15+
16+
private TextView tvTitle;
17+
private ListView listView;
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
setContentView(R.layout.activity_report);
23+
24+
tvTitle = (TextView) findViewById(R.id.tv_title);
25+
listView = (ListView) findViewById(R.id.listView);
26+
27+
/*tvTitle.setText("REPORT (" + MTHelper.getInstance().getFirstDay() + " - "
28+
+ MTHelper.getInstance().getLastDay() + ")");*/
29+
30+
31+
}
32+
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/helper/MTHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ private void initPeriod() {
257257
}
258258

259259
public String getFirstDay() {
260-
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
260+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
261261
return dateFormat.format(period.getFirst());
262262
}
263263

264264
public String getLastDay() {
265-
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
265+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
266266
return dateFormat.format(period.getLast());
267267
}
268268
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.blogspot.e_kanivets.moneytracker.model;
2+
3+
import android.util.Pair;
4+
5+
import java.util.ArrayList;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
9+
/**
10+
* Created by eugene on 11/09/14.
11+
*/
12+
public class Report {
13+
14+
private List<Record> records;
15+
private List<Pair<String, Integer>> reportList;
16+
17+
public Report(List<Record> records) {
18+
this.records = records;
19+
makeReport();
20+
}
21+
22+
public List<Pair<String, Integer>> getReportList() {
23+
return reportList;
24+
}
25+
26+
private void makeReport() {
27+
HashMap<String, Integer> map = new HashMap<String, Integer>();
28+
29+
for(Record record : records) {
30+
int sum = 0;
31+
//If category has already exist add to it
32+
if(map.containsKey(record.getCategory())) {
33+
sum = map.get(record.getCategory());
34+
}
35+
36+
//Add or subtract price
37+
if(record.isIncome()) {
38+
map.put(record.getCategory(), sum + record.getPrice());
39+
} else {
40+
map.put(record.getCategory(), sum - record.getPrice());
41+
}
42+
}
43+
44+
//Convert HashMap to ArrayList
45+
reportList = new ArrayList<Pair<String, Integer>>();
46+
for(String name : map.keySet()) {
47+
reportList.add(new Pair<String, Integer>(name, map.get(name)));
48+
}
49+
}
50+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:orientation="vertical" android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:background="@color/light_grey">
7+
8+
<TextView
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:textAppearance="?android:attr/textAppearanceLarge"
12+
android:text="@string/report"
13+
android:background="@color/yellow_light"
14+
android:textColor="@color/white"
15+
android:gravity="center"
16+
android:textAllCaps="true"
17+
android:id="@+id/tv_title" />
18+
19+
<ListView
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:id="@+id/listView"
23+
android:layout_gravity="center_horizontal" />
24+
25+
</LinearLayout>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
android:layout_height="wrap_content"
1212
android:textAppearance="?android:attr/textAppearanceLarge"
1313
android:text="@string/change_date"
14-
android:background="@color/blue"
14+
android:background="@color/yellow_light"
1515
android:textColor="@color/white"
1616
android:gravity="center"
1717
android:textAllCaps="true"

0 commit comments

Comments
 (0)