]> git.ktnx.net Git - mobile-ledger.git/commitdiff
some renames to better reflect the function
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 20 Dec 2018 18:01:46 +0000 (18:01 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 20 Dec 2018 18:01:46 +0000 (18:01 +0000)
app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java
app/src/main/java/net/ktnx/mobileledger/TransactionListAdapter.java
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/async/SaveTransactionTask.java
app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java
app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java [deleted file]

index 22b518a04efaef45ded25667966e8e9267fe4177..c34a80043d2bd42ccdf02d5ff0b112a38b628dc4 100644 (file)
@@ -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);
     }
index 267b759e38889104f3011f127953e9ff0bac6b42..bae5a536c1b8db9ce232a74be182401432048e8f 100644 (file)
@@ -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<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());
index 13941806240b07f42173e545dc3243b583b25270..190aa7ed543cb9918706fd1591b1068acb4febab 100644 (file)
@@ -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(
index ac9c7c91a73d116aebe715159453e6c668af2150..5bca52ff99e5d6072fabe44bb047a4013597b9dc 100644 (file)
@@ -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<LedgerTransaction, Void, Void
         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()));
index adb45fb93a857dae34a1c09c53a3477b8e6bd07b..3919ad141e431f39da7673be2ca3ecd835d29b32 100644 (file)
@@ -31,10 +31,10 @@ import java.util.Iterator;
 
 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());
@@ -45,7 +45,7 @@ public class LedgerTransaction {
     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) {
@@ -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<LedgerTransactionItem> getItemsIterator() {
-        return new Iterator<LedgerTransactionItem>() {
+    public Iterator<LedgerTransactionAccount> getAccountsIterator() {
+        return new Iterator<LedgerTransactionAccount>() {
             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 (file)
index 0000000..04ea9c0
--- /dev/null
@@ -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 <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();
+    }
+}
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 (file)
index 1084258..0000000
+++ /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 <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();
-    }
-}