make transaction header row always have Id of 0
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 11 Mar 2021 06:23:45 +0000 (08:23 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 11 Mar 2021 06:43:32 +0000 (08:43 +0200)
there's onle one header, and having a stable Id avoids visual flicker
when the list is updated

app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java

index 4ed8a65d6298c118c208e6dbfbb5a4ec2b8b459f..36b457ff4bf76bc1c0973a1db085196c2f3ee4e3 100644 (file)
@@ -865,11 +865,17 @@ public class NewTransactionModel extends ViewModel {
 
     static abstract class Item {
         private static int idDispenser = 0;
 
     static abstract class Item {
         private static int idDispenser = 0;
-        protected int id;
+        protected final int id;
         private Item() {
         private Item() {
-            synchronized (Item.class) {
-                id = ++idDispenser;
-            }
+            if (this instanceof TransactionHead)
+                id = 0;
+            else
+                synchronized (Item.class) {
+                    id = ++idDispenser;
+                }
+        }
+        public Item(int id) {
+            this.id = id;
         }
         public static Item from(Item origin) {
             if (origin instanceof TransactionHead)
         }
         public static Item from(Item origin) {
             if (origin instanceof TransactionHead)
@@ -929,7 +935,7 @@ public class NewTransactionModel extends ViewModel {
             this.description = description;
         }
         public TransactionHead(TransactionHead origin) {
             this.description = description;
         }
         public TransactionHead(TransactionHead origin) {
-            id = origin.id;
+            super(origin.id);
             date = origin.date;
             description = origin.description;
             comment = origin.comment;
             date = origin.date;
             description = origin.description;
             comment = origin.comment;
@@ -1030,7 +1036,7 @@ public class NewTransactionModel extends ViewModel {
         private boolean isLast = false;
         private int accountNameCursorPosition;
         public TransactionAccount(TransactionAccount origin) {
         private boolean isLast = false;
         private int accountNameCursorPosition;
         public TransactionAccount(TransactionAccount origin) {
-            id = origin.id;
+            super(origin.id);
             accountName = origin.accountName;
             amount = origin.amount;
             amountSet = origin.amountSet;
             accountName = origin.accountName;
             amount = origin.amount;
             amountSet = origin.amountSet;