abstract public class TemplateDetailsItem {
private final Type type;
protected Long id;
- protected Long position;
+ protected long position;
protected TemplateDetailsItem(Type type) {
this.type = type;
else
header.setDateYearMatchGroup(ph.getDateYearMatchGroup());
+ header.setFallback(ph.isFallback());
+
return header;
}
else if (p instanceof TemplateAccount) {
acc.setAccountCommentMatchGroup(pa.getAccountCommentMatchGroup());
if (pa.getCurrencyMatchGroup() == null) {
- final Integer currencyId = pa.getCurrency();
- if (currencyId != null && currencyId > 0)
- acc.setCurrency(Currency.loadById(currencyId));
+ acc.setCurrency(pa.getCurrencyObject());
}
else
acc.setCurrencyMatchGroup(pa.getCurrencyMatchGroup());
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);
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 {
PossiblyMatchedValue.withLiteralString("");
private final PossiblyMatchedValue<Float> amount =
PossiblyMatchedValue.withLiteralFloat(null);
- private final PossiblyMatchedValue<Currency> currency = new PossiblyMatchedValue<>();
+ private final PossiblyMatchedValue<net.ktnx.mobileledger.db.Currency> currency =
+ new PossiblyMatchedValue<>();
private boolean negateAmount;
public AccountRow() {
super(Type.ACCOUNT_ITEM);
public void setCurrencyMatchGroup(int group) {
currency.setMatchGroup(group);
}
- public Currency getCurrency() {
+ public net.ktnx.mobileledger.db.Currency getCurrency() {
return currency.getValue();
}
- public void setCurrency(Currency currency) {
+ public void setCurrency(net.ktnx.mobileledger.db.Currency currency) {
this.currency.setValue(currency);
}
public int getAccountNameMatchGroup() {
public boolean hasLiteralAccountComment() {
return accountComment.hasLiteralValue();
}
+ public boolean hasLiteralCurrency() { return currency.hasLiteralValue(); }
public boolean equalContents(AccountRow o) {
if (position != o.position) {
Logger.debug("cmpAcc",
public void switchToLiteralAmount() {
amount.switchToLiteral();
}
+ public void switchToLiteralCurrency() {
+ currency.switchToLiteral();
+ }
public void switchToLiteralAccountName() {
accountName.switchToLiteral();
}
result.setNegateAmount(negateAmount ? true : null);
}
+ if (currency.hasLiteralValue()) {
+ net.ktnx.mobileledger.db.Currency c = currency.getValue();
+ result.setCurrency((c == null) ? null : c.getId());
+ }
+ else {
+ result.setCurrencyMatchGroup(currency.getMatchGroup());
+ }
+
return result;
}
+ public boolean isEmpty() {
+ return accountName.isEmpty() && accountComment.isEmpty() && amount.isEmpty();
+ }
}
public static class Header extends 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);
}
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;
}
compiledPattern = null;
testMatch = new SpannableString(testText);
- testMatch.setSpan(notMatchedSpan(), 0, testText.length() - 1,
- Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ if (!testText.isEmpty())
+ testMatch.setSpan(notMatchedSpan(), 0, testText.length() - 1,
+ Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
}
@NonNull
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) {
else
result.setDateDayMatchGroup(dateDay.getMatchGroup());
+ result.setFallback(isFallback);
+
return result;
}
public SpannableString getTestMatch() {