From 35de61e97302f23f3e7d18e99e97b2f78277ba18 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 25 Apr 2021 21:51:44 +0300 Subject: [PATCH] small step towards support for currency in transaction templates --- .../ui/new_transaction/NewTransactionModel.java | 8 +++++++- .../mobileledger/ui/templates/TemplateDetailsAdapter.java | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java index 2bcf82fb..54bb31af 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java @@ -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; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java index fa76664e..eae2ba33 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java @@ -818,6 +818,8 @@ class TemplateDetailsAdapter extends RecyclerView.Adapter selectAccountRowDetailSource(v, AccDetail.ACCOUNT)); b.templateDetailsAccountNameSource.setOnClickListener( -- 2.39.5