Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
android:name=".activity.record.AddRecordActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.Default"
android:windowSoftInputMode="adjustResize" />
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".activity.account.AddAccountActivity"
android:label="@string/title_add_account"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ class AccountOperationsFragment : BaseFragment() {
val type = if (it.fromAccountId == account.id) Record.TYPE_EXPENSE else Record.TYPE_INCOME
val title = constructRecordTitle(type, it)
val category = Category(getString(R.string.transfer).toLowerCase())
val notes = getString(R.string.account_transfer)
val price = if (type == Record.TYPE_EXPENSE) it.fromAmount else it.toAmount
val decimals = if (type == Record.TYPE_EXPENSE) it.fromDecimals else it.toDecimals

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

return records.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class AddRecordActivity : BaseBackActivity() {
record?.let { record ->
etTitle.setText(record.title)
etCategory.setText(record.category?.name.orEmpty())
etNotes.setText(record.notes)
etPrice.setText(formatController.formatPrecisionNone(record.fullPrice))
}
}
Expand All @@ -102,6 +103,7 @@ class AddRecordActivity : BaseBackActivity() {
// Restrict ';' for input, because it's used as delimiter when exporting
etTitle.filters = arrayOf<InputFilter>(SemicolonInputFilter())
etCategory.filters = arrayOf<InputFilter>(SemicolonInputFilter())
etNotes.filters = arrayOf<InputFilter>(SemicolonInputFilter())

tvDate.setOnClickListener { selectDate() }
tvTime.setOnClickListener { selectTime() }
Expand Down Expand Up @@ -262,6 +264,7 @@ class AddRecordActivity : BaseBackActivity() {

var title = etTitle.text.toString().trim()
val category = etCategory.text.toString().trim()
val notes = etNotes.text.toString().trim()
val price = etPrice.text.toString().toDouble()
val account = accountList[spinnerAccount.selectedItemPosition]

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

if (mode == Mode.MODE_ADD) {
recordController.create(Record(timestamp, type, title,
Category(category), price, account, account.currency))
Category(category), notes, price, account, account.currency))
} else if (mode == Mode.MODE_EDIT) {
recordController.update(Record(record?.id ?: -1,
timestamp, type, title, Category(category), price, account, account.currency))
timestamp, type, title, Category(category), notes, price, account, account.currency))
}

autoCompleter.addRecordTitleCategoryPair(title, category)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ record = validateRecord(record);

completedRecordList.add(
new Record(record.getId(), record.getTime(), record.getType(), record.getTitle(), category,
record.getPrice(), account, currency, record.getDecimals()));
record.getNotes(), record.getPrice(), account, currency, record.getDecimals()));
}

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

return new Record(record.getId(), record.getTime(), record.getType(), record.getTitle(), category,
record.getPrice(), record.getAccount(), record.getCurrency(), record.getDecimals());
record.getNotes(), record.getPrice(), record.getAccount(), record.getCurrency(), record.getDecimals());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public List<String> getRecordsForExport(long fromDate, long toDate) {
sb.append(Head.ACCOUNT_ID).append(Head.DELIMITER);
sb.append(Head.TITLE).append(Head.DELIMITER);
sb.append(Head.CATEGORY).append(Head.DELIMITER);
sb.append(Head.NOTES).append(Head.DELIMITER);
sb.append(Head.PRICE).append(Head.DELIMITER);
sb.append(Head.CURRENCY);

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

sb.append(category == null ? "NONE" : category.getName()).append(Head.DELIMITER);
sb.append(record.getNotes()).append(Head.DELIMITER);
sb.append(record.getType() == 0 ? record.getFullPrice()
: -record.getFullPrice()).append(Head.DELIMITER);
sb.append(record.getCurrency() == null ? DbHelper.DEFAULT_ACCOUNT_CURRENCY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public interface Head {
String ACCOUNT_ID = "account_id";
String TITLE = "title";
String CATEGORY = "category";
String NOTES = "notes";
String PRICE = "price";
String CURRENCY = "currency";
String DELIMITER = ";";
int COLUMN_COUNT = 6;
int COLUMN_COUNT = 7;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ public List<Record> importRecordsFromCsv(@Nullable String csv) {
String accountIdCol = words[1];
String titleCol = words[2];
String categoryCol = words[3];
String priceCol = words[4];
String currencyCol = words[5];
String notesCol = words[4];
String priceCol = words[5];
String currencyCol = words[6];


try {
long time = Long.parseLong(timeCol);
long accountId = Long.parseLong(accountIdCol);
String title = titleCol.trim();
String categoryName = categoryCol.trim();
String notes = notesCol.trim();
double price = Double.parseDouble(priceCol);
String currency = currencyCol.trim();

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

Record record = new Record(time, type, title, category, Math.abs(price), account, currency);
Record record = new Record(time, type, title, category, notes, Math.abs(price), account, currency);
Record createdRecord = recordController.create(record);
if (createdRecord != null) recordList.add(createdRecord);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sealed class RecordItem {

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

data class Record(val title: String, val categoryName: String, val fullPrice: Double, val currency: String, val isIncome: Boolean) : RecordItem() {
constructor(record: com.blogspot.e_kanivets.moneytracker.entity.data.Record) : this(record.title, record.category?.name?.toString().orEmpty(), record.fullPrice, record.currency, record.isIncome)
data class Record(val title: String, val categoryName: String, val notes: String, val fullPrice: Double, val currency: String, val isIncome: Boolean) : RecordItem() {
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,57 +19,62 @@ public class Record extends BaseEntity implements Parcelable {
private final int type;
private final String title;
private final Category category;
private final String notes;
private final long price;
private final Account account;
private final String currency;
private final long decimals;

public Record(long id, long time, int type, String title, long categoryId, long price,
long accountId, String currency, long decimals) {
public Record(long id, long time, int type, String title, long categoryId, String notes,
long price, long accountId, String currency, long decimals) {
this.id = id;
this.time = time;
this.type = type;
this.title = title;
this.category = new Category(categoryId, null);
this.notes = notes;
this.price = price;
this.account = new Account(accountId, null, -1, null, 0, -1, false, -1);
this.currency = currency;
this.decimals = decimals;
}

public Record(long id, long time, int type, String title, Category category, long price,
Account account, String currency, long decimals) {
public Record(long id, long time, int type, String title, Category category, String notes,
long price, Account account, String currency, long decimals) {
this.id = id;
this.time = time;
this.type = type;
this.title = title;
this.category = category;
this.notes = notes;
this.price = price;
this.account = account;
this.currency = currency;
this.decimals = decimals;
}

public Record(long id, long time, int type, String title, Category category, double price,
Account account, String currency) {
public Record(long id, long time, int type, String title, Category category, String notes,
double price, Account account, String currency) {
this.id = id;
this.time = time;
this.type = type;
this.title = title;
this.category = category;
this.notes = notes;
this.account = account;
this.currency = currency;
this.price = getLong(price);
this.decimals = getDecimal(price);
}

public Record(long time, int type, String title, Category category, double price, Account account,
String currency) {
public Record(long time, int type, String title, Category category, String notes, double price,
Account account, String currency) {
this.id = -1;
this.time = time;
this.type = type;
this.title = title;
this.category = category;
this.notes = notes;
this.account = account;
this.currency = currency;
this.price = getLong(price);
Expand All @@ -82,6 +87,7 @@ protected Record(Parcel in) {
type = in.readInt();
title = in.readString();
category = in.readParcelable(Category.class.getClassLoader());
notes = in.readString();
price = in.readLong();
account = in.readParcelable(Account.class.getClassLoader());
currency = in.readString();
Expand Down Expand Up @@ -118,6 +124,9 @@ public Category getCategory() {
return category;
}


public String getNotes() { return notes; }

public long getPrice() {
return price;
}
Expand Down Expand Up @@ -173,6 +182,7 @@ public String toString() {

sb.append("time = ").append(time).append(", ");
sb.append("category = ").append(category).append(", ");
sb.append("notes = ").append(notes).append(", ");
sb.append("price = ").append(price).append(", ");
sb.append("account = ").append(account).append(", ");
sb.append("currency = ").append(currency).append(", ");
Expand All @@ -191,6 +201,7 @@ public boolean equals(Object o) {
&& this.type == record.getType()
&& equals(this.title, record.getTitle())
&& this.category.equals(record.getCategory())
&& equals(this.notes, record.getNotes())
&& this.price == record.getPrice()
&& this.account.equals(record.getAccount())
&& equals(this.currency, record.getCurrency())
Expand All @@ -210,6 +221,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(type);
dest.writeString(title);
dest.writeParcelable(category, 0);
dest.writeString(notes);
dest.writeLong(price);
dest.writeParcelable(account, 0);
dest.writeString(currency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DbHelper extends SQLiteOpenHelper {

/* DB_VERSION = 1 */
public static final String DB_NAME = "database";
public static final int DB_VERSION = 5;
public static final int DB_VERSION = 6;
public static final String TABLE_RECORDS = "records";
public static final String TABLE_CATEGORIES = "categories";

Expand Down Expand Up @@ -59,6 +59,9 @@ public class DbHelper extends SQLiteOpenHelper {
public static final String ARCHIVED_COLUMN = "archived";
public static final String COLOR_COLUMN = "color";

/* DB_VERSION = 6 */
public static final String NOTES_COLUMN = "notes";

public DbHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
Expand All @@ -69,7 +72,8 @@ public void onCreate(SQLiteDatabase db) {
//createDbVersion2(db);
//createDbVersion3(db);
//createDbVersion4(db);
createDbVersion5(db);
//createDbVersion5(db);
createDbVersion6(db);
}

@Override
Expand Down Expand Up @@ -158,6 +162,22 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.setTransactionSuccessful();
db.endTransaction();
}

if (oldVersion < 6) {
db.beginTransaction();

/* Add notes column to the records table */
db.execSQL("ALTER TABLE " + TABLE_RECORDS + " ADD COLUMN "
+ NOTES_COLUMN + " TEXT;");

/* Set the notes as empty string for all the record*/
ContentValues contentValues = new ContentValues();
contentValues.put(NOTES_COLUMN, "");
db.update(DbHelper.TABLE_RECORDS, contentValues, null, null);

db.setTransactionSuccessful();
db.endTransaction();
}
}

@SuppressWarnings("unused")
Expand Down Expand Up @@ -325,6 +345,49 @@ private void createDbVersion5(SQLiteDatabase db) {
insertDefaultAccount(db);
}

private void createDbVersion6(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_RECORDS + "("
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ TIME_COLUMN + " INTEGER,"
+ TYPE_COLUMN + " INTEGER,"
+ TITLE_COLUMN + " TEXT,"
+ CATEGORY_ID_COLUMN + " INTEGER,"
+ NOTES_COLUMN + " TEXT,"
+ PRICE_COLUMN + " INTEGER,"
+ ACCOUNT_ID_COLUMN + " INTEGER,"
+ CURRENCY_COLUMN + " TEXT,"
+ DECIMALS_COLUMN + " INTEGER);");

db.execSQL("CREATE TABLE " + TABLE_CATEGORIES + "("
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ NAME_COLUMN + " TEXT" + ");");

db.execSQL("CREATE TABLE " + TABLE_ACCOUNTS + "("
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ CREATED_AT_COLUMN + " INTEGER,"
+ TITLE_COLUMN + " TEXT,"
+ CUR_SUM_COLUMN + " INTEGER,"
+ CURRENCY_COLUMN + " TEXT,"
+ DECIMALS_COLUMN + " INTEGER,"
+ GOAL_COLUMN + " REAL,"
+ ARCHIVED_COLUMN + " INTEGER,"
+ COLOR_COLUMN + " INTEGER);");

db.execSQL("CREATE TABLE " + TABLE_TRANSFERS + "("
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ TIME_COLUMN + " INTEGER,"
+ FROM_ACCOUNT_ID_COLUMN + " INTEGER,"
+ TO_ACCOUNT_ID_COLUMN + " INTEGER,"
+ FROM_AMOUNT_COLUMN + " INTEGER,"
+ TO_AMOUNT_COLUMN + " INTEGER,"
+ DECIMALS_FROM_COLUMN + " INTEGER,"
+ DECIMALS_TO_COLUMN + " INTEGER);");

createRatesTable(db);

insertDefaultAccount(db);
}

private void createRatesTable(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_RATES + "("
+ ID_COLUMN + " INTEGER PRIMARY KEY AUTOINCREMENT,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected ContentValues contentValues(@Nullable Record record) {
contentValues.put(DbHelper.TYPE_COLUMN, record.getType());
contentValues.put(DbHelper.TITLE_COLUMN, record.getTitle());
contentValues.put(DbHelper.CATEGORY_ID_COLUMN, record.getCategory().getId());
contentValues.put(DbHelper.NOTES_COLUMN, record.getNotes());
contentValues.put(DbHelper.PRICE_COLUMN, record.getPrice());
contentValues.put(DbHelper.ACCOUNT_ID_COLUMN, record.getAccount().getId());
contentValues.put(DbHelper.CURRENCY_COLUMN, record.getCurrency());
Expand All @@ -64,6 +65,7 @@ protected List<Record> getListFromCursor(Cursor cursor) {
int typeColIndex = cursor.getColumnIndex(DbHelper.TYPE_COLUMN);
int titleColIndex = cursor.getColumnIndex(DbHelper.TITLE_COLUMN);
int categoryColIndex = cursor.getColumnIndex(DbHelper.CATEGORY_ID_COLUMN);
int notesColIndex = cursor.getColumnIndex(DbHelper.NOTES_COLUMN);
int priceColIndex = cursor.getColumnIndex(DbHelper.PRICE_COLUMN);
int accountIdColIndex = cursor.getColumnIndex(DbHelper.ACCOUNT_ID_COLUMN);
int currencyColIndex = cursor.getColumnIndex(DbHelper.CURRENCY_COLUMN);
Expand All @@ -75,6 +77,7 @@ protected List<Record> getListFromCursor(Cursor cursor) {
cursor.getInt(typeColIndex),
cursor.getString(titleColIndex),
cursor.getLong(categoryColIndex),
cursor.getString(notesColIndex),
cursor.getLong(priceColIndex),
cursor.getLong(accountIdColIndex),
cursor.getString(currencyColIndex),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ private List<Record> convertRecordList(List<Record> recordList) {
int decConvertedPrice = (int) Math.round(convertedPrice * 100 - intConvertedPrice * 100);

Record convertedRecord = new Record(record.getId(), record.getTime(), record.getType(),
record.getTitle(), record.getCategory(), intConvertedPrice, record.getAccount(),
currency, decConvertedPrice);
record.getTitle(), record.getCategory(), record.getNotes(), intConvertedPrice,
record.getAccount(), currency, decConvertedPrice);

convertedRecordList.add(convertedRecord);
}
Expand Down
Loading