]> git.ktnx.net Git - mobile-ledger.git/commitdiff
NT: turn on commodity setting when loading transaction with commodities
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 4 Apr 2022 19:20:21 +0000 (22:20 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 4 Apr 2022 19:20:21 +0000 (22:20 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java

index a87cb22fade82ed0d6c6d5edb5e6983425460879..2ae7b5e1b4eebf8ebb48564255d66ab86a888f70 100644 (file)
@@ -530,6 +530,7 @@ public class NewTransactionModel extends ViewModel {
         int singleNegativeIndex = -1;
         int singlePositiveIndex = -1;
         int negativeCount = 0;
+        boolean hasCurrency = false;
         for (int i = 0; i < accounts.size(); i++) {
             LedgerTransactionAccount acc = accounts.get(i);
             TransactionAccount item = new TransactionAccount(acc.getAccountName(),
@@ -559,6 +560,10 @@ public class NewTransactionModel extends ViewModel {
             }
             else
                 item.resetAmount();
+
+            if (item.getCurrency()
+                    .length() > 0)
+                hasCurrency = true;
         }
         if (BuildConfig.DEBUG)
             dumpItemList("Loaded previous transaction", newList);
@@ -572,9 +577,12 @@ public class NewTransactionModel extends ViewModel {
             moveItemLast(newList, singlePositiveIndex);
         }
 
+        final boolean foundTransactionHasCurrency = hasCurrency;
         Misc.onMainThread(() -> {
             setItems(newList);
             noteFocusChanged(1, FocusedElement.Amount);
+            if (foundTransactionHasCurrency)
+                showCurrency.setValue(true);
         });
     }
     /**
@@ -764,8 +772,8 @@ public class NewTransactionModel extends ViewModel {
                                 !Misc.equalStrings(acc.getAmountHint(), hint))
                             {
                                 Logger.debug("submittable",
-                                        String.format("Setting amount hint of {%s} to %s [%s]",
-                                                acc.toString(), hint, balCurrency));
+                                        String.format("Setting amount hint of {%s} to %s [%s]", acc,
+                                                hint, balCurrency));
                                 acc.setAmountHint(hint);
                                 listChanged = true;
                             }
@@ -1060,7 +1068,7 @@ public class NewTransactionModel extends ViewModel {
                 b.append(String.format(" '%s'", description));
 
             if (date != null)
-                b.append(String.format("@%s", date.toString()));
+                b.append(String.format("@%s", date));
 
             if (!TextUtils.isEmpty(comment))
                 b.append(String.format(" /%s/", comment));
@@ -1298,8 +1306,7 @@ public class NewTransactionModel extends ViewModel {
             equal = equal && Misc.equalStrings(currency, other.currency) && isLast == other.isLast;
 
             Logger.debug("new-trans",
-                    String.format("Comparing {%s} and {%s}: %s", this.toString(), other.toString(),
-                            equal));
+                    String.format("Comparing {%s} and {%s}: %s", this, other, equal));
             return equal;
         }
         public int getAccountNameCursorPosition() {