X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FMobileLedgerProfile.java;h=7214e2b0f8b2680a45723695fcda1453559f9fbe;hb=2ae4f914cd2cc40645ede8a4a7f68a07f479164b;hp=6b847ec103c1cb91aa5a2ea34e0a155632dae751;hpb=0a73337c99e2074aa7e7228204289896342ec636;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index 6b847ec1..7214e2b0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -173,8 +173,8 @@ public final class MobileLedgerProfile { db.endTransaction(); } } - public static ArrayList mergeAccountLists(List oldList, - List newList) { + public static ArrayList mergeAccountListsFromWeb(List oldList, + List newList) { LedgerAccount oldAcc, newAcc; ArrayList merged = new ArrayList<>(); @@ -214,18 +214,20 @@ public final class MobileLedgerProfile { continue; } - // two items with same account names; merge UI-controlled fields - oldAcc.setExpanded(newAcc.isExpanded()); - oldAcc.setAmountsExpanded(newAcc.amountsExpanded()); - merged.add(oldAcc); + // two items with same account names; forward-merge UI-controlled fields + // it is important that the result list contains a new LedgerAccount instance + // so that the change is propagated to the UI + newAcc.setExpanded(oldAcc.isExpanded()); + newAcc.setAmountsExpanded(oldAcc.amountsExpanded()); + merged.add(newAcc); } return merged; } - public void mergeAccountList(List newList) { + public void mergeAccountListFromWeb(List newList) { try (LockHolder l = accountsLocker.lockForWriting()) { - allAccounts = mergeAccountLists(allAccounts, newList); + allAccounts = mergeAccountListsFromWeb(allAccounts, newList); updateAccountsMap(allAccounts); } } @@ -689,7 +691,7 @@ public final class MobileLedgerProfile { db.endTransaction(); } - mergeAccountList(list); + mergeAccountListFromWeb(list); updateDisplayedAccounts(); } public synchronized Locker lockAccountsForWriting() { @@ -726,7 +728,7 @@ public final class MobileLedgerProfile { List transactions) { storeAccountAndTransactionListAsync(accounts, transactions, false); - mergeAccountList(accounts); + mergeAccountListFromWeb(accounts); updateDisplayedAccounts(); allTransactions.postValue(transactions);