]> git.ktnx.net Git - mobile-ledger.git/commitdiff
offer fallback templates only when no other template matches
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 18 Feb 2021 19:17:33 +0000 (21:17 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 18 Feb 2021 19:17:33 +0000 (21:17 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java

index 241be0b183ed21a7942387052b095486ea91698f..5edf252d72858ceccacef8663fe388e897a7810f 100644 (file)
@@ -114,6 +114,7 @@ public class NewTransactionFragment extends QRScanCapableFragment {
                                                         .getTemplateDAO()
                                                         .getTemplates();
         allTemplates.observe(getViewLifecycleOwner(), templateHeaders -> {
+            ArrayList<TemplateHeader> matchingFallbackTemplates = new ArrayList<>();
             ArrayList<TemplateHeader> 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)