]> git.ktnx.net Git - mobile-ledger.git/commitdiff
New transaction: fix clearing the single negative amount broken after ReecyclerView...
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 13 Nov 2019 19:43:41 +0000 (21:43 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 13 Nov 2019 19:43:52 +0000 (21:43 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java

index 21752a4467c56a829c60dccb69fd0fb61bff2370..6844b6ce3d743f471db420ec7d1723dd33f1cd26 100644 (file)
@@ -21,7 +21,6 @@ import android.database.Cursor;
 import android.view.LayoutInflater;
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
-import android.widget.TableRow;
 
 import androidx.annotation.NonNull;
 import androidx.recyclerview.widget.RecyclerView;
@@ -139,7 +138,8 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
 
             tr = profile.loadTransaction(transactionId);
             ArrayList<LedgerTransactionAccount> accounts = tr.getAccounts();
-            TableRow firstNegative = null;
+            NewTransactionModel.Item firstNegative = null;
+            boolean singleNegative = false;
             int negativeCount = 0;
             for (int i = 0; i < accounts.size(); i++) {
                 LedgerTransactionAccount acc = accounts.get(i);
@@ -152,12 +152,28 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
 
                 item.getAccount()
                     .setAccountName(acc.getAccountName());
-                if (acc.isAmountSet()) item.getAccount()
-                                           .setAmount(acc.getAmount());
-                else item.getAccount()
-                         .resetAmount();
+                if (acc.isAmountSet()) {
+                    item.getAccount()
+                        .setAmount(acc.getAmount());
+                    if (acc.getAmount() < 0) {
+                        if (firstNegative == null) {
+                            firstNegative = item;
+                            singleNegative = true;
+                        }
+                        else
+                            singleNegative = false;
+                    }
+                }
+                else
+                    item.getAccount()
+                        .resetAmount();
                 notifyItemChanged(i + 1);
             }
+
+            if (singleNegative) {
+                firstNegative.getAccount()
+                             .resetAmount();
+            }
         }
         model.checkTransactionSubmittable(this);
         model.setFocusedItem(1);