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

Commit 20ca370

Browse files
author
Evgeniy Kanivets
committed
Fixed bug with convertation long to int in moment of reading date from DB
1 parent a9e98f8 commit 20ca370

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {
5555
convertView = layoutInflater.inflate(R.layout.view_record, null);
5656

5757
TextView tvTime = (TextView) convertView.findViewById(R.id.tv_date_and_time);
58+
TextView tvSign = (TextView) convertView.findViewById(R.id.tv_sign);
5859
TextView tvPrice = (TextView) convertView.findViewById(R.id.tv_price);
5960
TextView tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
6061
TextView tvCategory = (TextView) convertView.findViewById(R.id.tv_category);
@@ -64,8 +65,8 @@ public View getView(final int position, View convertView, ViewGroup parent) {
6465
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
6566
tvTime.setText(dateFormat.format(new Date(records.get(position).getTime())));
6667

67-
tvPrice.setText((records.get(position).isIncome() ? "+ " : "- ")
68-
+ Integer.toString(records.get(position).getPrice()));
68+
tvSign.setText(records.get(position).isIncome() ? "+ " : "- ");
69+
tvPrice.setText(Integer.toString(records.get(position).getPrice()));
6970
tvTitle.setText(records.get(position).getTitle());
7071
tvCategory.setText(records.get(position).getCategory());
7172

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void initialize() {
7777
do {
7878
//Read a record from DB
7979
Record record = new Record(cursor.getInt(idColIndex),
80-
cursor.getInt(timeColIndex),
80+
cursor.getLong(timeColIndex),
8181
cursor.getInt(typeColIndex),
8282
cursor.getString(titleColIndex),
8383
cursor.getInt(categoryColIndex),
@@ -99,11 +99,12 @@ public void addRecord(long time, int type, String title, String category, int pr
9999
//Add record to DB
100100
SQLiteDatabase db = dbHelper.getWritableDatabase();
101101

102+
Log.d(Constants.TAG, "add time = " + time);
102103
ContentValues contentValues = new ContentValues();
103104
contentValues.put("time", time);
104105
contentValues.put("type", type);
105106
contentValues.put("title", title);
106-
contentValues.put("category_id", 1);
107+
contentValues.put("category_id", MTHelper.getInstance().getCategoryIdByName(category));
107108
contentValues.put("price", price);
108109

109110
int id = (int) db.insert(Constants.TABLE_RECORDS, null, contentValues);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.blogspot.e_kanivets.moneytracker.model;
22

3+
import android.util.Log;
4+
35
import com.blogspot.e_kanivets.moneytracker.helper.MTHelper;
6+
import com.blogspot.e_kanivets.moneytracker.util.Constants;
47

58
/**
69
* Created by eugene on 01/09/14.
@@ -24,6 +27,8 @@ public Record(int id, long time, int type, String title, int categoryId, int pri
2427
this.price = price;
2528

2629
category = MTHelper.getInstance().getCategoryById(categoryId);
30+
31+
Log.d(Constants.TAG, "id = " + categoryId + " category = " + category);
2732
}
2833

2934
public int getId() {

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,48 @@
1919
android:layout_height="wrap_content"
2020
android:layout_gravity="center">
2121

22+
<TextView
23+
android:layout_width="20dp"
24+
android:layout_height="match_parent"
25+
android:text="+"
26+
android:id="@+id/tv_sign"
27+
android:textSize="18dp"
28+
android:gravity="center"
29+
android:layout_gravity="center"
30+
android:minWidth="5dp"
31+
android:layout_marginLeft="10dp" />
32+
2233
<TextView
2334
android:layout_width="match_parent"
2435
android:layout_height="wrap_content"
2536
android:text="New Text"
2637
android:id="@+id/tv_price"
27-
android:textSize="20dp"
38+
android:textSize="18dp"
2839
android:layout_weight="1.15"
2940
android:gravity="center|left"
30-
android:layout_gravity="center_vertical"
31-
android:layout_marginLeft="10dp" />
41+
android:layout_gravity="center_vertical" />
3242

3343
<TextView
3444
android:layout_width="match_parent"
3545
android:layout_height="wrap_content"
3646
android:text="New Text"
3747
android:id="@+id/tv_title"
38-
android:textSize="20dp"
48+
android:textSize="18dp"
3949
android:layout_weight="1"
40-
android:gravity="center"
41-
android:layout_gravity="center_vertical" />
50+
android:layout_gravity="center_vertical"
51+
android:gravity="left"
52+
android:layout_marginLeft="2dp" />
4253

4354
<TextView
4455
android:layout_width="match_parent"
4556
android:layout_height="wrap_content"
4657
android:text="New Text"
4758
android:id="@+id/tv_category"
48-
android:textSize="20dp"
59+
android:textSize="18dp"
4960
android:layout_weight="1"
50-
android:gravity="center"
51-
android:layout_gravity="center_vertical" />
61+
android:layout_gravity="center_vertical"
62+
android:gravity="left"
63+
android:layout_marginLeft="2dp" />
5264

5365
<Button
5466
android:layout_width="30dp"

0 commit comments

Comments
 (0)