]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java
add fallback flag to templates
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / TemplateDetailsItem.java
index f158f413196dace141b2f9f6cdb6f1e9cb1d92fe..2eb3346df313e6c9ae040e84e05aa594d1856064 100644 (file)
@@ -47,7 +47,7 @@ import java.util.regex.PatternSyntaxException;
 abstract public class TemplateDetailsItem {
     private final Type type;
     protected Long id;
-    protected Long position;
+    protected long position;
 
     protected TemplateDetailsItem(Type type) {
         this.type = type;
@@ -98,6 +98,8 @@ abstract public class TemplateDetailsItem {
             else
                 header.setDateYearMatchGroup(ph.getDateYearMatchGroup());
 
+            header.setFallback(ph.isFallback());
+
             return header;
         }
         else if (p instanceof TemplateAccount) {
@@ -174,7 +176,7 @@ abstract public class TemplateDetailsItem {
     public long getPosition() {
         return position;
     }
-    public void setPosition(Long position) {
+    public void setPosition(long position) {
         this.position = position;
     }
     abstract public String getProblem(@NonNull Resources r, int patternGroupCount);
@@ -278,6 +280,12 @@ abstract public class TemplateDetailsItem {
                 return "grp:" + matchGroup;
             return "<null>";
         }
+        public boolean isEmpty() {
+            if (literalValue)
+                return value == null || Misc.emptyIsNull(value.toString()) == null;
+
+            return matchGroup > 0;
+        }
     }
 
     public static class TYPE {
@@ -421,6 +429,9 @@ abstract public class TemplateDetailsItem {
 
             return result;
         }
+        public boolean isEmpty() {
+            return accountName.isEmpty() && accountComment.isEmpty() && amount.isEmpty();
+        }
     }
 
     public static class Header extends TemplateDetailsItem {
@@ -437,6 +448,7 @@ abstract public class TemplateDetailsItem {
         private PossiblyMatchedValue<Integer> dateMonth = PossiblyMatchedValue.withLiteralInt(null);
         private PossiblyMatchedValue<Integer> dateDay = PossiblyMatchedValue.withLiteralInt(null);
         private SpannableString testMatch;
+        private boolean isFallback;
         private Header() {
             super(Type.HEADER);
         }
@@ -454,12 +466,20 @@ abstract public class TemplateDetailsItem {
             dateYear = new PossiblyMatchedValue<>(origin.dateYear);
             dateMonth = new PossiblyMatchedValue<>(origin.dateMonth);
             dateDay = new PossiblyMatchedValue<>(origin.dateDay);
+
+            isFallback = origin.isFallback;
         }
         private static StyleSpan capturedSpan() { return new StyleSpan(Typeface.BOLD); }
         private static UnderlineSpan matchedSpan() { return new UnderlineSpan(); }
         private static ForegroundColorSpan notMatchedSpan() {
             return new ForegroundColorSpan(Color.GRAY);
         }
+        public boolean isFallback() {
+            return isFallback;
+        }
+        public void setFallback(boolean fallback) {
+            this.isFallback = fallback;
+        }
         public String getName() {
             return name;
         }
@@ -594,7 +614,7 @@ abstract public class TemplateDetailsItem {
             return Misc.equalStrings(name, o.name) && Misc.equalStrings(pattern, o.pattern) &&
                    Misc.equalStrings(testText, o.testText) &&
                    Misc.equalStrings(patternError, o.patternError) &&
-                   Objects.equals(testMatch, o.testMatch);
+                   Objects.equals(testMatch, o.testMatch) && isFallback == o.isFallback;
         }
         public String getMatchGroupText(int group) {
             if (compiledPattern != null && testText != null) {
@@ -664,6 +684,8 @@ abstract public class TemplateDetailsItem {
             else
                 result.setDateDayMatchGroup(dateDay.getMatchGroup());
 
+            result.setFallback(isFallback);
+
             return result;
         }
         public SpannableString getTestMatch() {