From 160edb0e0fe58f5076329e8622db414001895530 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 20 Dec 2018 18:01:46 +0000 Subject: [PATCH] some renames to better reflect the function --- .../mobileledger/NewTransactionActivity.java | 10 ++++----- .../mobileledger/TransactionListAdapter.java | 6 ++--- .../async/RetrieveTransactionsTask.java | 7 +++--- .../async/SaveTransactionTask.java | 6 ++--- .../mobileledger/model/LedgerTransaction.java | 22 +++++++++---------- ...tem.java => LedgerTransactionAccount.java} | 8 +++---- 6 files changed, 30 insertions(+), 29 deletions(-) rename app/src/main/java/net/ktnx/mobileledger/model/{LedgerTransactionItem.java => LedgerTransactionAccount.java} (89%) 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/LedgerTransactionItem.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java similarity index 89% rename from app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java rename to app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java index 10842584..04ea9c06 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java @@ -19,23 +19,23 @@ package net.ktnx.mobileledger.model; import android.support.annotation.NonNull; -public class LedgerTransactionItem { +public class LedgerTransactionAccount { private String accountName; private float amount; private boolean amountSet; private String currency; - public LedgerTransactionItem(String accountName, float amount) { + public LedgerTransactionAccount(String accountName, float amount) { this(accountName, amount, null); } - public LedgerTransactionItem(String accountName, float amount, String currency) { + public LedgerTransactionAccount(String accountName, float amount, String currency) { this.accountName = accountName; this.amount = amount; this.amountSet = true; this.currency = currency; } - public LedgerTransactionItem(String accountName) { + public LedgerTransactionAccount(String accountName) { this.accountName = accountName; } -- 2.39.5