From b946450e2333ba9730631ddaacb1e7fdb7f32032 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 18 Feb 2021 21:17:33 +0200 Subject: [PATCH] offer fallback templates only when no other template matches --- .../ui/new_transaction/NewTransactionFragment.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java index 241be0b1..5edf252d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java @@ -114,6 +114,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { .getTemplateDAO() .getTemplates(); allTemplates.observe(getViewLifecycleOwner(), templateHeaders -> { + ArrayList matchingFallbackTemplates = new ArrayList<>(); ArrayList matchingTemplates = new ArrayList<>(); for (TemplateHeader ph : templateHeaders) { @@ -129,7 +130,10 @@ public class NewTransactionFragment extends QRScanCapableFragment { Logger.debug("pattern", String.format("Pattern '%s' [%s] matches '%s'", ph.getName(), patternSource, text)); - matchingTemplates.add(ph); + if (ph.isFallback()) + matchingFallbackTemplates.add(ph); + else + matchingTemplates.add(ph); } catch (ParcelFormatException e) { // ignored @@ -139,6 +143,9 @@ public class NewTransactionFragment extends QRScanCapableFragment { } } + if (matchingTemplates.isEmpty()) + matchingTemplates = matchingFallbackTemplates; + if (matchingTemplates.isEmpty()) alertNoTemplateMatch(text); else if (matchingTemplates.size() == 1) -- 2.39.5