import net.ktnx.mobileledger.async.SaveTransactionTask;
import net.ktnx.mobileledger.async.TaskCallback;
import net.ktnx.mobileledger.model.LedgerTransaction;
-import net.ktnx.mobileledger.model.LedgerTransactionItem;
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.ui.DatePickerFragment;
import net.ktnx.mobileledger.utils.MLDB;
TableRow row = (TableRow) table.getChildAt(i);
String acc = ((TextView) row.getChildAt(0)).getText().toString();
String amt = ((TextView) row.getChildAt(1)).getText().toString();
- LedgerTransactionItem item =
- amt.length() > 0 ? new LedgerTransactionItem(acc, Float.parseFloat(amt))
- : new LedgerTransactionItem(acc);
+ LedgerTransactionAccount item =
+ amt.length() > 0 ? new LedgerTransactionAccount(acc, Float.parseFloat(amt))
+ : new LedgerTransactionAccount(acc);
- tr.add_item(item);
+ tr.addAccount(item);
}
saver.execute(tr);
}
import android.widget.TextView;
import net.ktnx.mobileledger.model.LedgerTransaction;
-import net.ktnx.mobileledger.model.LedgerTransactionItem;
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.utils.MLDB;
import java.util.Iterator;
.setText(String.format("%s\n%s", tr.getDescription(), tr.getDate()));
TableLayout tbl = holder.row.findViewById(R.id.transaction_row_acc_amounts);
tbl.removeAllViews();
- for (Iterator<LedgerTransactionItem> it = tr.getItemsIterator(); it.hasNext(); ) {
- LedgerTransactionItem acc = it.next();
+ for (Iterator<LedgerTransactionAccount> it = tr.getAccountsIterator(); it.hasNext(); ) {
+ LedgerTransactionAccount acc = it.next();
TableRow row = new TableRow(holder.row.getContext());
TextView child = new TextView(ctx);
child.setText(acc.getShortAccountName());
import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.TransactionListActivity;
import net.ktnx.mobileledger.model.LedgerTransaction;
-import net.ktnx.mobileledger.model.LedgerTransactionItem;
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.utils.MLDB;
import net.ktnx.mobileledger.utils.NetworkUtil;
String acc_name = m.group(1);
String amount = m.group(2);
amount = amount.replace(',', '.');
- transaction.add_item(new LedgerTransactionItem(acc_name,
- Float.valueOf(amount)));
+ transaction.addAccount(
+ new LedgerTransactionAccount(acc_name,
+ Float.valueOf(amount)));
L(String.format("%s = %s", acc_name, amount));
}
else throw new IllegalStateException(
import android.util.Log;
import net.ktnx.mobileledger.model.LedgerTransaction;
-import net.ktnx.mobileledger.model.LedgerTransactionItem;
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.utils.NetworkUtil;
import net.ktnx.mobileledger.utils.UrlEncodedFormData;
params.add_pair("date", ltr.getDate());
params.add_pair("description", ltr.getDescription());
{
- Iterator<LedgerTransactionItem> items = ltr.getItemsIterator();
+ Iterator<LedgerTransactionAccount> items = ltr.getAccountsIterator();
while (items.hasNext()) {
- LedgerTransactionItem item = items.next();
+ LedgerTransactionAccount item = items.next();
params.add_pair("account", item.getAccountName());
if (item.isAmountSet())
params.add_pair("amount", String.format(Locale.US, "%1.2f", item.getAmount()));
public class LedgerTransaction {
private static final String DIGEST_TYPE = "SHA-256";
- public final Comparator<LedgerTransactionItem> comparator =
- new Comparator<LedgerTransactionItem>() {
+ public final Comparator<LedgerTransactionAccount> comparator =
+ new Comparator<LedgerTransactionAccount>() {
@Override
- public int compare(LedgerTransactionItem o1, LedgerTransactionItem o2) {
+ public int compare(LedgerTransactionAccount o1, LedgerTransactionAccount o2) {
int res = o1.getAccountName().compareTo(o2.getAccountName());
if (res != 0) return res;
res = o1.getCurrency().compareTo(o2.getCurrency());
private Integer id;
private String date;
private String description;
- private ArrayList<LedgerTransactionItem> items;
+ private ArrayList<LedgerTransactionAccount> items;
private String dataHash;
private boolean dataLoaded;
public LedgerTransaction(Integer id, String date, String description) {
public LedgerTransaction(int id) {
this(id, null, null);
}
- public void add_item(LedgerTransactionItem item) {
+ public void addAccount(LedgerTransactionAccount item) {
items.add(item);
dataHash = null;
}
this.description = description;
dataHash = null;
}
- public Iterator<LedgerTransactionItem> getItemsIterator() {
- return new Iterator<LedgerTransactionItem>() {
+ public Iterator<LedgerTransactionAccount> getAccountsIterator() {
+ return new Iterator<LedgerTransactionAccount>() {
private int pointer = 0;
@Override
public boolean hasNext() {
}
@Override
- public LedgerTransactionItem next() {
+ public LedgerTransactionAccount next() {
return hasNext() ? items.get(pointer++) : null;
}
};
db.execSQL("INSERT INTO transactions(id, date, description, data_hash) values(?,?,?,?)",
new Object[]{id, date, description, dataHash});
- for (LedgerTransactionItem item : items) {
+ for (LedgerTransactionAccount item : items) {
db.execSQL("INSERT INTO transaction_accounts(transaction_id, account_name, amount, " +
"currency) values(?, ?, ?, ?)",
new Object[]{id, item.getAccountName(), item.getAmount(), item.getCurrency()});
data.append('\0');
data.append(getDescription());
data.append('\0');
- for (LedgerTransactionItem item : items) {
+ for (LedgerTransactionAccount item : items) {
data.append(item.getAccountName());
data.append('\0');
data.append(item.getCurrency());
new String[]{String.valueOf(id)}))
{
while (cAcc.moveToNext()) {
- add_item(new LedgerTransactionItem(cAcc.getString(0), cAcc.getFloat(1),
+ addAccount(new LedgerTransactionAccount(cAcc.getString(0), cAcc.getFloat(1),
cAcc.getString(2)));
}
--- /dev/null
+/*
+ * Copyright © 2018 Damyan Ivanov.
+ * This file is part of Mobile-Ledger.
+ * Mobile-Ledger is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * Mobile-Ledger is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.model;
+
+import android.support.annotation.NonNull;
+
+public class LedgerTransactionAccount {
+ private String accountName;
+ private float amount;
+ private boolean amountSet;
+ private String currency;
+
+ public LedgerTransactionAccount(String accountName, float amount) {
+ this(accountName, amount, null);
+ }
+ public LedgerTransactionAccount(String accountName, float amount, String currency) {
+ this.accountName = accountName;
+ this.amount = amount;
+ this.amountSet = true;
+ this.currency = currency;
+ }
+
+ public LedgerTransactionAccount(String accountName) {
+ this.accountName = accountName;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+ public String getShortAccountName() {
+ String result = accountName;
+ result = result.replaceAll("(?<=^|:)(.)[^:]+(?=:)", "$1");
+ return result;
+ }
+
+ public void setAccountName(String accountName) {
+ this.accountName = accountName;
+ }
+
+ public float getAmount() {
+ if (!amountSet) throw new IllegalStateException("Account amount is not set");
+
+ return amount;
+ }
+
+ public void setAmount(float account_amount) {
+ this.amount = account_amount;
+ this.amountSet = true;
+ }
+
+ public void resetAmount() {
+ this.amountSet = false;
+ }
+
+ public boolean isAmountSet() {
+ return amountSet;
+ }
+ public String getCurrency() {
+ return currency;
+ }
+ @NonNull
+ public String toString() {
+ if (!amountSet) return "";
+
+ StringBuilder sb = new StringBuilder();
+ if (currency != null) {
+ sb.append(currency);
+ sb.append(' ');
+ }
+ sb.append(String.format("%,1.2f", amount));
+
+ return sb.toString();
+ }
+}
+++ /dev/null
-/*
- * Copyright © 2018 Damyan Ivanov.
- * This file is part of Mobile-Ledger.
- * Mobile-Ledger is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * Mobile-Ledger is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.model;
-
-import android.support.annotation.NonNull;
-
-public class LedgerTransactionItem {
- private String accountName;
- private float amount;
- private boolean amountSet;
- private String currency;
-
- public LedgerTransactionItem(String accountName, float amount) {
- this(accountName, amount, null);
- }
- public LedgerTransactionItem(String accountName, float amount, String currency) {
- this.accountName = accountName;
- this.amount = amount;
- this.amountSet = true;
- this.currency = currency;
- }
-
- public LedgerTransactionItem(String accountName) {
- this.accountName = accountName;
- }
-
- public String getAccountName() {
- return accountName;
- }
- public String getShortAccountName() {
- String result = accountName;
- result = result.replaceAll("(?<=^|:)(.)[^:]+(?=:)", "$1");
- return result;
- }
-
- public void setAccountName(String accountName) {
- this.accountName = accountName;
- }
-
- public float getAmount() {
- if (!amountSet) throw new IllegalStateException("Account amount is not set");
-
- return amount;
- }
-
- public void setAmount(float account_amount) {
- this.amount = account_amount;
- this.amountSet = true;
- }
-
- public void resetAmount() {
- this.amountSet = false;
- }
-
- public boolean isAmountSet() {
- return amountSet;
- }
- public String getCurrency() {
- return currency;
- }
- @NonNull
- public String toString() {
- if (!amountSet) return "";
-
- StringBuilder sb = new StringBuilder();
- if (currency != null) {
- sb.append(currency);
- sb.append(' ');
- }
- sb.append(String.format("%,1.2f", amount));
-
- return sb.toString();
- }
-}