Skip to content

Commit defbcd2

Browse files
author
Jana Hoch
committed
Merge branch 'feature-notes' into dev
2 parents 06445a8 + 84e53c5 commit defbcd2

File tree

19 files changed

+123
-24
lines changed

19 files changed

+123
-24
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
android:name=".activity.record.AddRecordActivity"
3131
android:screenOrientation="portrait"
3232
android:theme="@style/Theme.Default"
33-
android:windowSoftInputMode="adjustResize" />
33+
android:windowSoftInputMode="adjustPan" />
3434
<activity
3535
android:name=".activity.account.AddAccountActivity"
3636
android:label="@string/title_add_account"

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/account/edit/fragment/AccountOperationsFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ class AccountOperationsFragment : BaseFragment() {
5959
val type = if (it.fromAccountId == account.id) Record.TYPE_EXPENSE else Record.TYPE_INCOME
6060
val title = constructRecordTitle(type, it)
6161
val category = Category(getString(R.string.transfer).toLowerCase())
62+
val notes = "Account Transfer"
6263
val price = if (type == Record.TYPE_EXPENSE) it.fromAmount else it.toAmount
6364
val decimals = if (type == Record.TYPE_EXPENSE) it.fromDecimals else it.toDecimals
6465

65-
records += Record(it.id, it.time, type, title, category, price, account, account.currency, decimals)
66+
records += Record(it.id, it.time, type, title, category, notes, price, account, account.currency, decimals)
6667
}
6768

6869
return records.toList()

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/record/AddRecordActivity.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class AddRecordActivity : BaseBackActivity() {
9292
record?.let { record ->
9393
etTitle.setText(record.title)
9494
etCategory.setText(record.category?.name.orEmpty())
95+
etNotes.setText(record.notes)
9596
etPrice.setText(formatController.formatPrecisionNone(record.fullPrice))
9697
}
9798
}
@@ -102,6 +103,7 @@ class AddRecordActivity : BaseBackActivity() {
102103
// Restrict ';' for input, because it's used as delimiter when exporting
103104
etTitle.filters = arrayOf<InputFilter>(SemicolonInputFilter())
104105
etCategory.filters = arrayOf<InputFilter>(SemicolonInputFilter())
106+
etNotes.filters = arrayOf<InputFilter>(SemicolonInputFilter())
105107

106108
tvDate.setOnClickListener { selectDate() }
107109
tvTime.setOnClickListener { selectTime() }
@@ -262,6 +264,7 @@ class AddRecordActivity : BaseBackActivity() {
262264

263265
var title = etTitle.text.toString().trim()
264266
val category = etCategory.text.toString().trim()
267+
val notes = etNotes.text.toString().trim()
265268
val price = etPrice.text.toString().toDouble()
266269
val account = accountList[spinnerAccount.selectedItemPosition]
267270

@@ -271,10 +274,10 @@ class AddRecordActivity : BaseBackActivity() {
271274

272275
if (mode == Mode.MODE_ADD) {
273276
recordController.create(Record(timestamp, type, title,
274-
Category(category), price, account, account.currency))
277+
Category(category), notes, price, account, account.currency))
275278
} else if (mode == Mode.MODE_EDIT) {
276279
recordController.update(Record(record?.id ?: -1,
277-
timestamp, type, title, Category(category), price, account, account.currency))
280+
timestamp, type, title, Category(category), notes, price, account, account.currency))
278281
}
279282

280283
autoCompleter.addRecordTitleCategoryPair(title, category)

app/src/main/java/com/blogspot/e_kanivets/moneytracker/controller/data/RecordController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ record = validateRecord(record);
115115

116116
completedRecordList.add(
117117
new Record(record.getId(), record.getTime(), record.getType(), record.getTitle(), category,
118-
record.getPrice(), account, currency, record.getDecimals()));
118+
record.getNotes(), record.getPrice(), account, currency, record.getDecimals()));
119119
}
120120

121121
return completedRecordList;
@@ -143,6 +143,6 @@ private Record validateRecord(@NonNull Record record) {
143143
Category category = categoryController.readOrCreate(record.getCategory().getName());
144144

145145
return new Record(record.getId(), record.getTime(), record.getType(), record.getTitle(), category,
146-
record.getPrice(), record.getAccount(), record.getCurrency(), record.getDecimals());
146+
record.getNotes(), record.getPrice(), record.getAccount(), record.getCurrency(), record.getDecimals());
147147
}
148148
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/controller/external/ExportController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public List<String> getRecordsForExport(long fromDate, long toDate) {
3434
sb.append(Head.ACCOUNT_ID).append(Head.DELIMITER);
3535
sb.append(Head.TITLE).append(Head.DELIMITER);
3636
sb.append(Head.CATEGORY).append(Head.DELIMITER);
37+
sb.append(Head.NOTES).append(Head.DELIMITER);
3738
sb.append(Head.PRICE).append(Head.DELIMITER);
3839
sb.append(Head.CURRENCY);
3940

@@ -60,6 +61,7 @@ public List<String> getRecordsForExport(long fromDate, long toDate) {
6061
category = categoryController.read(record.getCategory().getId());
6162

6263
sb.append(category == null ? "NONE" : category.getName()).append(Head.DELIMITER);
64+
sb.append(record.getNotes()).append(Head.DELIMITER);
6365
sb.append(record.getType() == 0 ? record.getFullPrice()
6466
: -record.getFullPrice()).append(Head.DELIMITER);
6567
sb.append(record.getCurrency() == null ? DbHelper.DEFAULT_ACCOUNT_CURRENCY

app/src/main/java/com/blogspot/e_kanivets/moneytracker/controller/external/Head.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ public interface Head {
1111
String ACCOUNT_ID = "account_id";
1212
String TITLE = "title";
1313
String CATEGORY = "category";
14+
String NOTES = "notes";
1415
String PRICE = "price";
1516
String CURRENCY = "currency";
1617
String DELIMITER = ";";
17-
int COLUMN_COUNT = 6;
18+
int COLUMN_COUNT = 7;
1819
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/controller/external/ImportController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ public List<Record> importRecordsFromCsv(@Nullable String csv) {
3838
String accountIdCol = words[1];
3939
String titleCol = words[2];
4040
String categoryCol = words[3];
41-
String priceCol = words[4];
42-
String currencyCol = words[5];
41+
String notesCol = words[4];
42+
String priceCol = words[5];
43+
String currencyCol = words[6];
4344

4445
try {
4546
long time = Long.parseLong(timeCol);
4647
long accountId = Long.parseLong(accountIdCol);
4748
String title = titleCol.trim();
4849
String categoryName = categoryCol.trim();
50+
String notes = notesCol.trim();
4951
double price = Double.parseDouble(priceCol);
5052
String currency = currencyCol.trim();
5153

@@ -59,7 +61,7 @@ public List<Record> importRecordsFromCsv(@Nullable String csv) {
5961
Category category = new Category(categoryName);
6062
Account account = new Account(accountId, "MOCK", -1, currency, 0, -1, false, 0);
6163

62-
Record record = new Record(time, type, title, category, Math.abs(price), account, currency);
64+
Record record = new Record(time, type, title, category, notes, Math.abs(price), account, currency);
6365
Record createdRecord = recordController.create(record);
6466
if (createdRecord != null) recordList.add(createdRecord);
6567
} catch (Exception e) {

app/src/main/java/com/blogspot/e_kanivets/moneytracker/entity/RecordItem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sealed class RecordItem {
44

55
data class Header(val date: String) : RecordItem()
66

7-
data class Record(val title: String, val categoryName: String, val fullPrice: Double, val currency: String, val isIncome: Boolean) : RecordItem() {
8-
constructor(record: com.blogspot.e_kanivets.moneytracker.entity.data.Record) : this(record.title, record.category?.name?.toString().orEmpty(), record.fullPrice, record.currency, record.isIncome)
7+
data class Record(val title: String, val categoryName: String, val notes: String, val fullPrice: Double, val currency: String, val isIncome: Boolean) : RecordItem() {
8+
constructor(record: com.blogspot.e_kanivets.moneytracker.entity.data.Record) : this(record.title, record.category?.name?.toString().orEmpty(), record.notes, record.fullPrice, record.currency, record.isIncome)
99
}
1010
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/entity/data/Record.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,62 @@ public class Record extends BaseEntity implements Parcelable {
1919
private final int type;
2020
private final String title;
2121
private final Category category;
22+
private final String notes;
2223
private final long price;
2324
private final Account account;
2425
private final String currency;
2526
private final long decimals;
2627

27-
public Record(long id, long time, int type, String title, long categoryId, long price,
28-
long accountId, String currency, long decimals) {
28+
public Record(long id, long time, int type, String title, long categoryId, String notes,
29+
long price, long accountId, String currency, long decimals) {
2930
this.id = id;
3031
this.time = time;
3132
this.type = type;
3233
this.title = title;
3334
this.category = new Category(categoryId, null);
35+
this.notes = notes;
3436
this.price = price;
3537
this.account = new Account(accountId, null, -1, null, 0, -1, false, -1);
3638
this.currency = currency;
3739
this.decimals = decimals;
3840
}
3941

40-
public Record(long id, long time, int type, String title, Category category, long price,
41-
Account account, String currency, long decimals) {
42+
public Record(long id, long time, int type, String title, Category category, String notes,
43+
long price, Account account, String currency, long decimals) {
4244
this.id = id;
4345
this.time = time;
4446
this.type = type;
4547
this.title = title;
4648
this.category = category;
49+
this.notes = notes;
4750
this.price = price;
4851
this.account = account;
4952
this.currency = currency;
5053
this.decimals = decimals;
5154
}
5255

53-
public Record(long id, long time, int type, String title, Category category, double price,
54-
Account account, String currency) {
56+
public Record(long id, long time, int type, String title, Category category, String notes,
57+
double price, Account account, String currency) {
5558
this.id = id;
5659
this.time = time;
5760
this.type = type;
5861
this.title = title;
5962
this.category = category;
63+
this.notes = notes;
6064
this.account = account;
6165
this.currency = currency;
6266
this.price = getLong(price);
6367
this.decimals = getDecimal(price);
6468
}
6569

66-
public Record(long time, int type, String title, Category category, double price, Account account,
67-
String currency) {
70+
public Record(long time, int type, String title, Category category, String notes, double price,
71+
Account account, String currency) {
6872
this.id = -1;
6973
this.time = time;
7074
this.type = type;
7175
this.title = title;
7276
this.category = category;
77+
this.notes = notes;
7378
this.account = account;
7479
this.currency = currency;
7580
this.price = getLong(price);
@@ -82,6 +87,7 @@ protected Record(Parcel in) {
8287
type = in.readInt();
8388
title = in.readString();
8489
category = in.readParcelable(Category.class.getClassLoader());
90+
notes = in.readString();
8591
price = in.readLong();
8692
account = in.readParcelable(Account.class.getClassLoader());
8793
currency = in.readString();
@@ -118,6 +124,9 @@ public Category getCategory() {
118124
return category;
119125
}
120126

127+
128+
public String getNotes() { return notes; }
129+
121130
public long getPrice() {
122131
return price;
123132
}
@@ -173,6 +182,7 @@ public String toString() {
173182

174183
sb.append("time = ").append(time).append(", ");
175184
sb.append("category = ").append(category).append(", ");
185+
sb.append("notes = ").append(notes).append(", ");
176186
sb.append("price = ").append(price).append(", ");
177187
sb.append("account = ").append(account).append(", ");
178188
sb.append("currency = ").append(currency).append(", ");
@@ -191,6 +201,7 @@ public boolean equals(Object o) {
191201
&& this.type == record.getType()
192202
&& equals(this.title, record.getTitle())
193203
&& this.category.equals(record.getCategory())
204+
&& equals(this.notes, record.getNotes())
194205
&& this.price == record.getPrice()
195206
&& this.account.equals(record.getAccount())
196207
&& equals(this.currency, record.getCurrency())
@@ -210,6 +221,7 @@ public void writeToParcel(Parcel dest, int flags) {
210221
dest.writeInt(type);
211222
dest.writeString(title);
212223
dest.writeParcelable(category, 0);
224+
dest.writeString(notes);
213225
dest.writeLong(price);
214226
dest.writeParcelable(account, 0);
215227
dest.writeString(currency);

app/src/main/java/com/blogspot/e_kanivets/moneytracker/repo/DbHelper.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class DbHelper extends SQLiteOpenHelper {
1515

1616
/* DB_VERSION = 1 */
1717
public static final String DB_NAME = "database";
18-
public static final int DB_VERSION = 5;
18+
public static final int DB_VERSION = 6;
1919
public static final String TABLE_RECORDS = "records";
2020
public static final String TABLE_CATEGORIES = "categories";
2121

@@ -59,6 +59,9 @@ public class DbHelper extends SQLiteOpenHelper {
5959
public static final String ARCHIVED_COLUMN = "archived";
6060
public static final String COLOR_COLUMN = "color";
6161

62+
/* DB_VERSION = 6 */
63+
public static final String NOTES_COLUMN = "notes";
64+
6265
public DbHelper(Context context) {
6366
super(context, DB_NAME, null, DB_VERSION);
6467
}
@@ -69,7 +72,8 @@ public void onCreate(SQLiteDatabase db) {
6972
//createDbVersion2(db);
7073
//createDbVersion3(db);
7174
//createDbVersion4(db);
72-
createDbVersion5(db);
75+
//createDbVersion5(db);
76+
createDbVersion6(db);
7377
}
7478

7579
@Override
@@ -158,6 +162,14 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
158162
db.setTransactionSuccessful();
159163
db.endTransaction();
160164
}
165+
166+
if (oldVersion < 6) {
167+
db.beginTransaction();
168+
169+
/* Add notes column to the records table */
170+
db.execSQL("ALTER TABLE " + TABLE_RECORDS + " ADD COLUMN "
171+
+ NOTES_COLUMN + " TEXT;");
172+
}
161173
}
162174

163175
@SuppressWarnings("unused")
@@ -325,6 +337,49 @@ private void createDbVersion5(SQLiteDatabase db) {
325337
insertDefaultAccount(db);
326338
}
327339

340+
private void createDbVersion6(SQLiteDatabase db) {
341+
db.execSQL("CREATE TABLE " + TABLE_RECORDS + "("
342+
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"
343+
+ TIME_COLUMN + " INTEGER,"
344+
+ TYPE_COLUMN + " INTEGER,"
345+
+ TITLE_COLUMN + " TEXT,"
346+
+ CATEGORY_ID_COLUMN + " INTEGER,"
347+
+ NOTES_COLUMN + " TEXT,"
348+
+ PRICE_COLUMN + " INTEGER,"
349+
+ ACCOUNT_ID_COLUMN + " INTEGER,"
350+
+ CURRENCY_COLUMN + " TEXT,"
351+
+ DECIMALS_COLUMN + " INTEGER);");
352+
353+
db.execSQL("CREATE TABLE " + TABLE_CATEGORIES + "("
354+
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"
355+
+ NAME_COLUMN + " TEXT" + ");");
356+
357+
db.execSQL("CREATE TABLE " + TABLE_ACCOUNTS + "("
358+
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"
359+
+ CREATED_AT_COLUMN + " INTEGER,"
360+
+ TITLE_COLUMN + " TEXT,"
361+
+ CUR_SUM_COLUMN + " INTEGER,"
362+
+ CURRENCY_COLUMN + " TEXT,"
363+
+ DECIMALS_COLUMN + " INTEGER,"
364+
+ GOAL_COLUMN + " REAL,"
365+
+ ARCHIVED_COLUMN + " INTEGER,"
366+
+ COLOR_COLUMN + " INTEGER);");
367+
368+
db.execSQL("CREATE TABLE " + TABLE_TRANSFERS + "("
369+
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"
370+
+ TIME_COLUMN + " INTEGER,"
371+
+ FROM_ACCOUNT_ID_COLUMN + " INTEGER,"
372+
+ TO_ACCOUNT_ID_COLUMN + " INTEGER,"
373+
+ FROM_AMOUNT_COLUMN + " INTEGER,"
374+
+ TO_AMOUNT_COLUMN + " INTEGER,"
375+
+ DECIMALS_FROM_COLUMN + " INTEGER,"
376+
+ DECIMALS_TO_COLUMN + " INTEGER);");
377+
378+
createRatesTable(db);
379+
380+
insertDefaultAccount(db);
381+
}
382+
328383
private void createRatesTable(SQLiteDatabase db) {
329384
db.execSQL("CREATE TABLE " + TABLE_RATES + "("
330385
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"

0 commit comments

Comments
 (0)