From: Damyan Ivanov Date: Thu, 20 Dec 2018 18:01:46 +0000 (+0000) Subject: some renames to better reflect the function X-Git-Tag: v0.3~196 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=160edb0e0fe58f5076329e8622db414001895530 some renames to better reflect the function --- diff --git a/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java index 22b518a0..c34a8004 100644 --- a/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java @@ -54,7 +54,7 @@ import android.widget.TextView; 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; @@ -154,11 +154,11 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal 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); } diff --git a/app/src/main/java/net/ktnx/mobileledger/TransactionListAdapter.java b/app/src/main/java/net/ktnx/mobileledger/TransactionListAdapter.java index 267b759e..bae5a536 100644 --- a/app/src/main/java/net/ktnx/mobileledger/TransactionListAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/TransactionListAdapter.java @@ -32,7 +32,7 @@ import android.widget.TableRow; 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; @@ -57,8 +57,8 @@ class TransactionListAdapter .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 it = tr.getItemsIterator(); it.hasNext(); ) { - LedgerTransactionItem acc = it.next(); + for (Iterator 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()); diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index 13941806..190aa7ed 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -26,7 +26,7 @@ import android.util.Log; 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; @@ -215,8 +215,9 @@ public class RetrieveTransactionsTask extends 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( diff --git a/app/src/main/java/net/ktnx/mobileledger/async/SaveTransactionTask.java b/app/src/main/java/net/ktnx/mobileledger/async/SaveTransactionTask.java index ac9c7c91..5bca52ff 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/SaveTransactionTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/SaveTransactionTask.java @@ -22,7 +22,7 @@ import android.os.AsyncTask; 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; @@ -74,9 +74,9 @@ public class SaveTransactionTask extends AsyncTask items = ltr.getItemsIterator(); + Iterator 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())); diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java index adb45fb9..3919ad14 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java @@ -31,10 +31,10 @@ import java.util.Iterator; public class LedgerTransaction { private static final String DIGEST_TYPE = "SHA-256"; - public final Comparator comparator = - new Comparator() { + public final Comparator comparator = + new Comparator() { @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()); @@ -45,7 +45,7 @@ public class LedgerTransaction { private Integer id; private String date; private String description; - private ArrayList items; + private ArrayList items; private String dataHash; private boolean dataLoaded; public LedgerTransaction(Integer id, String date, String description) { @@ -62,7 +62,7 @@ public class LedgerTransaction { public LedgerTransaction(int id) { this(id, null, null); } - public void add_item(LedgerTransactionItem item) { + public void addAccount(LedgerTransactionAccount item) { items.add(item); dataHash = null; } @@ -80,8 +80,8 @@ public class LedgerTransaction { this.description = description; dataHash = null; } - public Iterator getItemsIterator() { - return new Iterator() { + public Iterator getAccountsIterator() { + return new Iterator() { private int pointer = 0; @Override public boolean hasNext() { @@ -89,7 +89,7 @@ public class LedgerTransaction { } @Override - public LedgerTransactionItem next() { + public LedgerTransactionAccount next() { return hasNext() ? items.get(pointer++) : null; } }; @@ -102,7 +102,7 @@ public class LedgerTransaction { 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()}); @@ -117,7 +117,7 @@ public class LedgerTransaction { 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()); @@ -158,7 +158,7 @@ public class LedgerTransaction { 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))); } diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java new file mode 100644 index 00000000..04ea9c06 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java @@ -0,0 +1,89 @@ +/* + * 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 . + */ + +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(); + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java deleted file mode 100644 index 10842584..00000000 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 . - */ - -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(); - } -}