]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java
explicit assert of non-null value
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / new_transaction / NewTransactionModel.java
index a87cb22fade82ed0d6c6d5edb5e6983425460879..d8f387b72696983f1fe9f87d0ae12e0a5b4d1be8 100644 (file)
@@ -487,7 +487,8 @@ public class NewTransactionModel extends ViewModel {
                                 "Should not happen: approved transaction has %d accounts for " +
                                 "currency %s", accounts.size(), currency));
                     accounts.get(0)
-                            .setAmount(-emptyAmountAccountBalance.get(currency));
+                            .setAmount(-Objects.requireNonNull(
+                                    emptyAmountAccountBalance.get(currency)));
                 });
             }
             else {
@@ -500,7 +501,8 @@ public class NewTransactionModel extends ViewModel {
                                 "Should not happen: approved transaction has %d accounts for " +
                                 "currency %s", accounts.size(), currency));
                     accounts.get(0)
-                            .setAmount(-emptyAmountAccountBalance.get(currency));
+                            .setAmount(-Objects.requireNonNull(
+                                    emptyAmountAccountBalance.get(currency)));
                 }
             }
         }
@@ -530,6 +532,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 +562,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 +579,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 +774,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 +1070,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 +1308,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() {