From: Damyan Ivanov Date: Thu, 18 Feb 2021 19:17:33 +0000 (+0200) Subject: offer fallback templates only when no other template matches X-Git-Tag: v0.17.0~82 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=b946450e2333ba9730631ddaacb1e7fdb7f32032;p=mobile-ledger.git offer fallback templates only when no other template matches --- 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)