]> git.ktnx.net Git - mobile-ledger.git/commitdiff
small step towards support for currency in transaction templates
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 25 Apr 2021 18:51:44 +0000 (21:51 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 25 Apr 2021 18:51:44 +0000 (21:51 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java
app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java

index 2bcf82fb8d46ce3d54d193436087eaf4bba83ba4..54bb31af257307abb6a7d9aac4fc252785a96367 100644 (file)
@@ -29,6 +29,7 @@ import androidx.lifecycle.Observer;
 import androidx.lifecycle.ViewModel;
 
 import net.ktnx.mobileledger.BuildConfig;
+import net.ktnx.mobileledger.db.Currency;
 import net.ktnx.mobileledger.db.DB;
 import net.ktnx.mobileledger.db.Profile;
 import net.ktnx.mobileledger.db.TemplateAccount;
@@ -290,11 +291,13 @@ public class NewTransactionModel extends ViewModel {
                   if (amount != null && acc.getNegateAmount() != null && acc.getNegateAmount())
                       amount = -amount;
 
-                  // TODO currency
                   TransactionAccount accRow = new TransactionAccount(accountName);
                   accRow.setComment(accountComment);
                   if (amount != null)
                       accRow.setAmount(amount);
+                  accRow.setCurrency(
+                          extractCurrencyFromMatches(matchResult, acc.getCurrencyMatchGroup(),
+                                  acc.getCurrencyObject()));
 
                   newItems.add(accRow);
               }
@@ -302,6 +305,9 @@ public class NewTransactionModel extends ViewModel {
               Misc.onMainThread(() -> replaceItems(newItems));
           });
     }
+    private String extractCurrencyFromMatches(MatchResult m, Integer group, Currency literal) {
+        return extractStringFromMatches(m, group, (literal == null) ? "" : literal.getName());
+    }
     private int extractIntFromMatches(MatchResult m, Integer group, Integer literal) {
         if (literal != null)
             return literal;
index fa76664ee7ae798fcf729a7cf00083729a598873..eae2ba33a56cdddfe5b9d6ef3cd6657b739493e0 100644 (file)
@@ -818,6 +818,8 @@ class TemplateDetailsAdapter extends RecyclerView.Adapter<TemplateDetailsAdapter
                     b.templateDetailsNegateAmountText.setVisibility(View.VISIBLE);
                 }
 
+                // TODO: currency
+
                 b.templateAccountNameSourceLabel.setOnClickListener(
                         v -> selectAccountRowDetailSource(v, AccDetail.ACCOUNT));
                 b.templateDetailsAccountNameSource.setOnClickListener(