From f973784f579d42988174acf0b24593aa23180fa6 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 11 Mar 2021 08:23:45 +0200 Subject: [PATCH] make transaction header row always have Id of 0 there's onle one header, and having a stable Id avoids visual flicker when the list is updated --- .../new_transaction/NewTransactionModel.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java index 4ed8a65d..36b457ff 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java @@ -865,11 +865,17 @@ public class NewTransactionModel extends ViewModel { static abstract class Item { private static int idDispenser = 0; - protected int id; + protected final int id; 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) @@ -929,7 +935,7 @@ public class NewTransactionModel extends ViewModel { this.description = description; } public TransactionHead(TransactionHead origin) { - id = origin.id; + super(origin.id); 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) { - id = origin.id; + super(origin.id); accountName = origin.accountName; amount = origin.amount; amountSet = origin.amountSet; -- 2.39.5