db.endTransaction();
}
}
- public static ArrayList<LedgerAccount> mergeAccountLists(List<LedgerAccount> oldList,
- List<LedgerAccount> newList) {
+ public static ArrayList<LedgerAccount> mergeAccountListsFromWeb(List<LedgerAccount> oldList,
+ List<LedgerAccount> newList) {
LedgerAccount oldAcc, newAcc;
ArrayList<LedgerAccount> merged = new ArrayList<>();
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<LedgerAccount> newList) {
+ public void mergeAccountListFromWeb(List<LedgerAccount> newList) {
try (LockHolder l = accountsLocker.lockForWriting()) {
- allAccounts = mergeAccountLists(allAccounts, newList);
+ allAccounts = mergeAccountListsFromWeb(allAccounts, newList);
updateAccountsMap(allAccounts);
}
}
db.endTransaction();
}
- mergeAccountList(list);
+ mergeAccountListFromWeb(list);
updateDisplayedAccounts();
}
public synchronized Locker lockAccountsForWriting() {
List<LedgerTransaction> transactions) {
storeAccountAndTransactionListAsync(accounts, transactions, false);
- mergeAccountList(accounts);
+ mergeAccountListFromWeb(accounts);
updateDisplayedAccounts();
allTransactions.postValue(transactions);