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

Commit a9e98f8

Browse files
author
Evgeniy Kanivets
committed
Added date and time label functionality
1 parent 9c84593 commit a9e98f8

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import com.blogspot.e_kanivets.moneytracker.model.Record;
1717
import com.blogspot.e_kanivets.moneytracker.util.Constants;
1818

19+
import java.text.SimpleDateFormat;
20+
import java.util.Date;
1921
import java.util.List;
2022

2123
/**
@@ -59,6 +61,9 @@ public View getView(final int position, View convertView, ViewGroup parent) {
5961

6062
Button bRemove = (Button) convertView.findViewById(R.id.b_remove);
6163

64+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
65+
tvTime.setText(dateFormat.format(new Date(records.get(position).getTime())));
66+
6267
tvPrice.setText((records.get(position).isIncome() ? "+ " : "- ")
6368
+ Integer.toString(records.get(position).getPrice()));
6469
tvTitle.setText(records.get(position).getTitle());

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ public List<Record> getRecords() {
9595
return records;
9696
}
9797

98-
public void addRecord(int time, int type, String title, String category, int price) {
98+
public void addRecord(long time, int type, String title, String category, int price) {
9999
//Add record to DB
100100
SQLiteDatabase db = dbHelper.getWritableDatabase();
101101

102102
ContentValues contentValues = new ContentValues();
103+
contentValues.put("time", time);
103104
contentValues.put("type", type);
104105
contentValues.put("title", title);
105106
contentValues.put("category_id", 1);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
public class Record {
99

1010
private int id;
11-
private int time;
11+
private long time;
1212
private int type;
1313
private String title;
1414
private int categoryId;
1515
private String category;
1616
private int price;
1717

18-
public Record(int id, int time, int type, String title, int categoryId, int price) {
18+
public Record(int id, long time, int type, String title, int categoryId, int price) {
1919
this.id = id;
2020
this.time = time;
2121
this.type = type;
@@ -42,6 +42,10 @@ public int getPrice() {
4242
return price;
4343
}
4444

45+
public long getTime() {
46+
return time;
47+
}
48+
4549
public boolean isIncome() {
4650
return type == 0;
4751
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/ui/AddExpenseDialog.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.blogspot.e_kanivets.moneytracker.util.Constants;
2727
import com.blogspot.e_kanivets.moneytracker.util.MTApp;
2828

29+
import java.util.Date;
30+
2931
/**
3032
* Created by eugene on 29/08/14.
3133
*/
@@ -64,7 +66,7 @@ public void onClick(View v) {
6466
String category = ((EditText) findViewById(R.id.et_category)).getText().toString();
6567
int price = Integer.parseInt(((EditText) findViewById(R.id.et_price)).getText().toString());
6668

67-
MTHelper.getInstance().addRecord(0, 1, title, category, price);
69+
MTHelper.getInstance().addRecord(new Date().getTime(), 1, title, category, price);
6870

6971
dismiss();
7072
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/ui/AddIncomeDialog.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import com.blogspot.e_kanivets.moneytracker.util.Constants;
2828
import com.blogspot.e_kanivets.moneytracker.util.MTApp;
2929

30+
import java.text.SimpleDateFormat;
31+
import java.util.Date;
32+
3033
/**
3134
* Created by eugene on 29/08/14.
3235
*/
@@ -65,7 +68,7 @@ public void onClick(View v) {
6568
String category = ((EditText) findViewById(R.id.et_category)).getText().toString();
6669
int price = Integer.parseInt(((EditText) findViewById(R.id.et_price)).getText().toString());
6770

68-
MTHelper.getInstance().addRecord(0, 0, title, category, price);
71+
MTHelper.getInstance().addRecord(new Date().getTime(), 0, title, category, price);
6972

7073
dismiss();
7174
}

0 commit comments

Comments
 (0)