From: Damyan Ivanov Date: Sun, 25 Apr 2021 18:51:44 +0000 (+0300) Subject: small step towards support for currency in transaction templates X-Git-Tag: v0.18.0~17 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=35de61e97302f23f3e7d18e99e97b2f78277ba18;p=mobile-ledger.git small step towards support for currency in transaction templates --- 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(