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

Commit 680da76

Browse files
author
Evgeniy Kanivets
committed
Fixed bug with wrong linking to category after first category creation
1 parent 9e0d8f7 commit 680da76

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public void initialize() {
5353
//Read a record from DB
5454
Category category = new Category(cursor.getInt(idColIndex),
5555
cursor.getString(nameColIndex));
56+
Log.d(Constants.TAG, "id = " + cursor.getInt(idColIndex) +
57+
" name = " + cursor.getString(nameColIndex));
5658

5759
//Add record to list
5860
categories.add(category);
@@ -82,6 +84,12 @@ public void initialize() {
8284
cursor.getString(titleColIndex),
8385
cursor.getInt(categoryColIndex),
8486
cursor.getInt(priceColIndex));
87+
Log.d(Constants.TAG, "id = " + cursor.getInt(idColIndex) +
88+
" time = " + cursor.getLong(timeColIndex) +
89+
" type = " + cursor.getInt(typeColIndex) +
90+
" title = " + cursor.getString(titleColIndex) +
91+
" category = " + cursor.getInt(categoryColIndex) +
92+
" price = " + cursor.getInt(priceColIndex));
8593

8694
//Add record to list
8795
records.add(record);
@@ -96,6 +104,12 @@ public List<Record> getRecords() {
96104
}
97105

98106
public void addRecord(long time, int type, String title, String category, int price) {
107+
//Add category if it does not exist yet
108+
if(getCategoryIdByName(category) == -1) {
109+
addCategory(category);
110+
}
111+
int category_id = getCategoryIdByName(category);
112+
99113
//Add record to DB
100114
SQLiteDatabase db = dbHelper.getWritableDatabase();
101115

@@ -110,11 +124,6 @@ public void addRecord(long time, int type, String title, String category, int pr
110124

111125
db.close();
112126

113-
if(getCategoryIdByName(category) == -1) {
114-
addCategory(category);
115-
}
116-
int category_id = getCategoryIdByName(category);
117-
118127
//Add record to app list
119128
records.add(new Record(id, time, type, title, category_id, price));
120129

@@ -183,6 +192,7 @@ public String getCategoryById(int id) {
183192

184193
public int getCategoryIdByName(String name) {
185194
for(Category category : categories) {
195+
Log.d(Constants.TAG, name + " " + category.getName() + " " + category.getName().equals(name));
186196
if(category.getName().equals(name)) {
187197
return category.getId();
188198
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ public AddExpenseDialog(Context context) {
4545
protected void onCreate(Bundle savedInstanceState) {
4646
super.onCreate(savedInstanceState);
4747

48-
//Justify width of dialog
48+
4949
View view = getLayoutInflater().inflate(R.layout.dialog_add_record, null);
5050
setContentView(view);
5151

52+
/* Justify width of dialog */
5253
ViewGroup.LayoutParams params = view.getLayoutParams();
5354
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
5455
params.width = Math.min(metrics.widthPixels-20, AppUtils.scaleValue(context, 700));

0 commit comments

Comments
 (0)