]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java
AccountRow.equalContents: compare positions too
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / TemplateDetailsItem.java
index 0f9cfe490b84e00f8053cb3b35947c49a5196c5f..f158f413196dace141b2f9f6cdb6f1e9cb1d92fe 100644 (file)
@@ -32,11 +32,13 @@ import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.db.TemplateAccount;
 import net.ktnx.mobileledger.db.TemplateBase;
 import net.ktnx.mobileledger.db.TemplateHeader;
+import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.Misc;
 
 import org.jetbrains.annotations.Contract;
 import org.jetbrains.annotations.NotNull;
 
+import java.util.Locale;
 import java.util.Objects;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -102,6 +104,7 @@ abstract public class TemplateDetailsItem {
             TemplateAccount pa = (TemplateAccount) p;
             AccountRow acc = createAccountRow();
             acc.setId(pa.getId());
+            acc.setPosition(pa.getPosition());
 
             if (pa.getAccountNameMatchGroup() == null)
                 acc.setAccountName(Misc.nullIsEmpty(pa.getAccountName()));
@@ -225,6 +228,11 @@ abstract public class TemplateDetailsItem {
             result.setValue(initialValue);
             return result;
         }
+        public void copyFrom(@NonNull PossiblyMatchedValue<T> origin) {
+            literalValue = origin.literalValue;
+            value = origin.value;
+            matchGroup = origin.matchGroup;
+        }
         public T getValue() {
             if (!literalValue)
                 throw new IllegalStateException("Value is not literal");
@@ -286,9 +294,19 @@ abstract public class TemplateDetailsItem {
                 PossiblyMatchedValue.withLiteralFloat(null);
         private final PossiblyMatchedValue<Currency> currency = new PossiblyMatchedValue<>();
         private boolean negateAmount;
-        private AccountRow() {
+        public AccountRow() {
             super(Type.ACCOUNT_ITEM);
         }
+        public AccountRow(AccountRow origin) {
+            super(Type.ACCOUNT_ITEM);
+            id = origin.id;
+            position = origin.position;
+            accountName.copyFrom(origin.accountName);
+            accountComment.copyFrom(origin.accountComment);
+            amount.copyFrom(origin.amount);
+            currency.copyFrom(origin.currency);
+            negateAmount = origin.negateAmount;
+        }
         public boolean isNegateAmount() {
             return negateAmount;
         }
@@ -360,8 +378,15 @@ abstract public class TemplateDetailsItem {
             return accountComment.hasLiteralValue();
         }
         public boolean equalContents(AccountRow o) {
+            if (position != o.position) {
+                Logger.debug("cmpAcc",
+                        String.format(Locale.US, "[%d] != [%d]: pos %d != pos %d", getId(),
+                                o.getId(), position, o.position));
+                return false;
+            }
             return amount.equals(o.amount) && accountName.equals(o.accountName) &&
-                   accountComment.equals(o.accountComment) && negateAmount == o.negateAmount;
+                   position == o.position && accountComment.equals(o.accountComment) &&
+                   negateAmount == o.negateAmount;
         }
         public void switchToLiteralAmount() {
             amount.switchToLiteral();