]> git.ktnx.net Git - mobile-ledger.git/commitdiff
replace transaction accounts iterator with a getter
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 21 Dec 2018 17:03:30 +0000 (17:03 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 21 Dec 2018 17:03:30 +0000 (17:03 +0000)
app/src/main/java/net/ktnx/mobileledger/TransactionListAdapter.java
app/src/main/java/net/ktnx/mobileledger/async/SaveTransactionTask.java
app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java
app/src/main/res/layout/transaction_list_fragment.xml
app/src/main/res/layout/transaction_list_row.xml

index 1ec01132a1505a4000f22f0d03424e308ad366ed..57de4c0c0666765367ad3677cf1e81e58087e58b 100644 (file)
@@ -57,8 +57,7 @@ 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<LedgerTransactionAccount> it = tr.getAccountsIterator(); it.hasNext(); ) {
-                LedgerTransactionAccount acc = it.next();
+            for (LedgerTransactionAccount acc : tr.getAccounts()) {
                 TableRow row = new TableRow(holder.row.getContext());
                 TextView child = new TextView(ctx);
                 child.setText(acc.getShortAccountName());
index 5bca52ff99e5d6072fabe44bb047a4013597b9dc..9cd669e215fea61d98b5dfb5f1e2eda334d96977 100644 (file)
@@ -32,7 +32,6 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -73,15 +72,11 @@ public class SaveTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
         if (token != null) params.add_pair("_token", token);
         params.add_pair("date", ltr.getDate());
         params.add_pair("description", ltr.getDescription());
-        {
-            Iterator<LedgerTransactionAccount> items = ltr.getAccountsIterator();
-            while (items.hasNext()) {
-                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()));
-                else params.add_pair("amount", "");
-            }
+        for (LedgerTransactionAccount acc : ltr.getAccounts()) {
+            params.add_pair("account", acc.getAccountName());
+            if (acc.isAmountSet())
+                params.add_pair("amount", String.format(Locale.US, "%1.2f", acc.getAmount()));
+            else params.add_pair("amount", "");
         }
 
         String body = params.toString();
index 3919ad141e431f39da7673be2ca3ecd835d29b32..40d1f5fe05c4dc99cded5bf2a5790f35733c0caf 100644 (file)
@@ -27,7 +27,6 @@ import java.nio.charset.Charset;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Comparator;
-import java.util.Iterator;
 
 public class LedgerTransaction {
     private static final String DIGEST_TYPE = "SHA-256";
@@ -45,17 +44,20 @@ public class LedgerTransaction {
     private Integer id;
     private String date;
     private String description;
-    private ArrayList<LedgerTransactionAccount> items;
-    private String dataHash;
-    private boolean dataLoaded;
+    private ArrayList<LedgerTransactionAccount> accounts;
     public LedgerTransaction(Integer id, String date, String description) {
         this.id = id;
         this.date = date;
         this.description = description;
-        this.items = new ArrayList<>();
+        this.accounts = new ArrayList<>();
         this.dataHash = null;
         dataLoaded = false;
     }
+    private String dataHash;
+    private boolean dataLoaded;
+    public ArrayList<LedgerTransactionAccount> getAccounts() {
+        return accounts;
+    }
     public LedgerTransaction(String date, String description) {
         this(null, date, description);
     }
@@ -63,7 +65,7 @@ public class LedgerTransaction {
         this(id, null, null);
     }
     public void addAccount(LedgerTransactionAccount item) {
-        items.add(item);
+        accounts.add(item);
         dataHash = null;
     }
     public String getDate() {
@@ -80,20 +82,6 @@ public class LedgerTransaction {
         this.description = description;
         dataHash = null;
     }
-    public Iterator<LedgerTransactionAccount> getAccountsIterator() {
-        return new Iterator<LedgerTransactionAccount>() {
-            private int pointer = 0;
-            @Override
-            public boolean hasNext() {
-                return pointer < items.size();
-            }
-
-            @Override
-            public LedgerTransactionAccount next() {
-                return hasNext() ? items.get(pointer++) : null;
-            }
-        };
-    }
     public int getId() {
         return id;
     }
@@ -102,7 +90,7 @@ public class LedgerTransaction {
         db.execSQL("INSERT INTO transactions(id, date, description, data_hash) values(?,?,?,?)",
                 new Object[]{id, date, description, dataHash});
 
-        for (LedgerTransactionAccount item : items) {
+        for (LedgerTransactionAccount item : accounts) {
             db.execSQL("INSERT INTO transaction_accounts(transaction_id, account_name, amount, " +
                        "currency) values(?, ?, ?, ?)",
                     new Object[]{id, item.getAccountName(), item.getAmount(), item.getCurrency()});
@@ -117,7 +105,7 @@ public class LedgerTransaction {
             data.append('\0');
             data.append(getDescription());
             data.append('\0');
-            for (LedgerTransactionAccount item : items) {
+            for (LedgerTransactionAccount item : accounts) {
                 data.append(item.getAccountName());
                 data.append('\0');
                 data.append(item.getCurrency());
index 19bb72fa3d875a213513c573ccd5f9e05c474dec..c871f2ad4213e11c25ad64c9aa10489044b026a2 100644 (file)
@@ -47,7 +47,8 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="1"
-            android:text="TextView" />
+            android:text="\?"
+            tools:ignore="HardcodedText" />
     </LinearLayout>
 
     <View
@@ -64,7 +65,6 @@
         android:layout_height="wrap_content"
         android:indeterminate="true"
         android:indeterminateBehavior="cycle"
-        android:progress="40"
         android:progressTint="@color/colorPrimary"
         android:visibility="gone"
         app:layout_constraintEnd_toEndOf="parent"
index 8a950efd6e2a19c2a143beaed6a0720437a855af..a31faad07c48b3b0f86f72e95d7329703585a247 100644 (file)
@@ -18,8 +18,9 @@
   ~ along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
   -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/transaction_row"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:minHeight="36dp"
     android:orientation="horizontal"
     android:paddingStart="8dp"
-    android:paddingEnd="8dp"
-    tools:showIn="@layout/transaction_list_fragment">
+    android:paddingEnd="8dp">
 
     <!--android:button="@drawable/checkbox_star_black"-->
 
     <TextView
         android:id="@+id/transaction_row_description"
         style="@style/account_summary_account_name"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="5"
         android:text="Sample description goes here."
         tools:ignore="HardcodedText" />
 
     <TableLayout
         android:id="@+id/transaction_row_acc_amounts"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent">
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="8dp"
+        android:layout_weight="5"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintStart_toEndOf="@id/transaction_row_description">
 
         <TableRow>
 
@@ -69,4 +76,4 @@
                 tools:ignore="HardcodedText" />
         </TableRow>
     </TableLayout>
-</LinearLayout>
\ No newline at end of file
+</android.support.constraint.ConstraintLayout>
\ No newline at end of file