+
+ // 5) a row with an empty account name or empty amount is guaranteed to exist for
+ // each commodity
+ for (String balCurrency : balance.currencies()) {
+ int currEmptyRows = itemsWithEmptyAccountForCurrency.size(balCurrency);
+ int currRows = itemsForCurrency.size(balCurrency);
+ int currAccounts = itemsWithAccountForCurrency.size(balCurrency);
+ int currAmounts = itemsWithAmountForCurrency.size(balCurrency);
+ if ((currEmptyRows == 0) &&
+ ((currRows == currAccounts) || (currRows == currAmounts)))
+ {
+ // perhaps there already is an unused empty row for another currency that
+ // is not used?
+// boolean foundIt = false;
+// for (Item item : emptyRows) {
+// Currency itemCurrency = item.getCurrency();
+// String itemCurrencyName =
+// (itemCurrency == null) ? "" : itemCurrency.getName();
+// if (Misc.isZero(balance.get(itemCurrencyName))) {
+// item.setCurrency(Currency.loadByName(balCurrency));
+// item.setAmountHint(
+// String.format("%1.2f", -balance.get(balCurrency)));
+// foundIt = true;
+// break;
+// }
+// }
+//
+// if (!foundIt)
+ adapter.addRow(balCurrency);
+ }
+ }
+
+ // drop extra empty rows, not needed
+ for (String currName : emptyRowsForCurrency.currencies()) {
+ List<Item> emptyItems = emptyRowsForCurrency.getList(currName);
+ while ((this.items.size() > 2) && (emptyItems.size() > 1)) {
+ Item item = emptyItems.get(1);
+ emptyItems.remove(1);
+ removeRow(item, adapter);
+ }
+
+ // unused currency, remove last item (which is also an empty one)
+ if ((items.size() > 2) && (emptyItems.size() == 1)) {
+ List<Item> currItems = itemsForCurrency.getList(currName);
+
+ if (currItems.size() == 1) {
+ Item item = emptyItems.get(0);
+ removeRow(item, adapter);
+ }
+ }