From: Damyan Ivanov Date: Thu, 18 Feb 2021 19:10:12 +0000 (+0200) Subject: more pattern → template renaming X-Git-Tag: v0.17.0~83 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=bd78203182126b68575ad14ed303ce9a9c225ad6;p=mobile-ledger.git more pattern → template renaming --- 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 6b120560..241be0b1 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 @@ -95,7 +95,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { args.putString(TemplatesActivity.ARG_ADD_TEMPLATE, scanned); requireContext().startActivity(intent, args); } - private void alertNoPatternMatch(String scanned) { + private void alertNoTemplateMatch(String scanned) { MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); builder.setCancelable(true) .setMessage(R.string.no_template_matches) @@ -110,13 +110,13 @@ public class NewTransactionFragment extends QRScanCapableFragment { if (Misc.emptyIsNull(text) == null) return; - LiveData> allPatterns = DB.get() - .getTemplateDAO() - .getTemplates(); - allPatterns.observe(getViewLifecycleOwner(), patternHeaders -> { - ArrayList matchingPatterns = new ArrayList<>(); + LiveData> allTemplates = DB.get() + .getTemplateDAO() + .getTemplates(); + allTemplates.observe(getViewLifecycleOwner(), templateHeaders -> { + ArrayList matchingTemplates = new ArrayList<>(); - for (TemplateHeader ph : patternHeaders) { + for (TemplateHeader ph : templateHeaders) { String patternSource = ph.getRegularExpression(); if (Misc.emptyIsNull(patternSource) == null) continue; @@ -129,7 +129,7 @@ public class NewTransactionFragment extends QRScanCapableFragment { Logger.debug("pattern", String.format("Pattern '%s' [%s] matches '%s'", ph.getName(), patternSource, text)); - matchingPatterns.add(ph); + matchingTemplates.add(ph); } catch (ParcelFormatException e) { // ignored @@ -139,31 +139,31 @@ public class NewTransactionFragment extends QRScanCapableFragment { } } - if (matchingPatterns.isEmpty()) - alertNoPatternMatch(text); - else if (matchingPatterns.size() == 1) - applyPattern(matchingPatterns.get(0), text); + if (matchingTemplates.isEmpty()) + alertNoTemplateMatch(text); + else if (matchingTemplates.size() == 1) + applyTemplate(matchingTemplates.get(0), text); else - choosePattern(matchingPatterns, text); + chooseTemplate(matchingTemplates, text); }); } - private void choosePattern(ArrayList matchingPatterns, String matchedText) { - final String patternNameColumn = "name"; + private void chooseTemplate(ArrayList matchingTemplates, String matchedText) { + final String templateNameColumn = "name"; AbstractCursor cursor = new AbstractCursor() { @Override public int getCount() { - return matchingPatterns.size(); + return matchingTemplates.size(); } @Override public String[] getColumnNames() { - return new String[]{"_id", patternNameColumn}; + return new String[]{"_id", templateNameColumn}; } @Override public String getString(int column) { if (column == 0) return String.valueOf(getPosition()); - return matchingPatterns.get(getPosition()) - .getName(); + return matchingTemplates.get(getPosition()) + .getName(); } @Override public short getShort(int column) { @@ -201,14 +201,14 @@ public class NewTransactionFragment extends QRScanCapableFragment { builder.setCancelable(true) .setTitle(R.string.choose_template_to_apply) .setIcon(R.drawable.ic_baseline_auto_graph_24) - .setSingleChoiceItems(cursor, -1, patternNameColumn, (dialog, which) -> { - applyPattern(matchingPatterns.get(which), matchedText); + .setSingleChoiceItems(cursor, -1, templateNameColumn, (dialog, which) -> { + applyTemplate(matchingTemplates.get(which), matchedText); dialog.dismiss(); }) .create() .show(); } - private void applyPattern(TemplateHeader patternHeader, String text) { + private void applyTemplate(TemplateHeader patternHeader, String text) { Pattern pattern = Pattern.compile(patternHeader.getRegularExpression()); Matcher m = pattern.matcher(text);