ArrayList<LedgerTransactionAccount> accounts = tr.getAccounts();
NewTransactionModel.Item firstNegative = null;
NewTransactionModel.Item firstPositive = null;
- boolean singleNegative = false;
- boolean singlePositive = false;
+ int singleNegativeIndex = -1;
+ int singlePositiveIndex = -1;
int negativeCount = 0;
for (int i = 0; i < accounts.size(); i++) {
LedgerTransactionAccount acc = accounts.get(i);
if (acc.getAmount() < 0) {
if (firstNegative == null) {
firstNegative = item;
- singleNegative = true;
+ singleNegativeIndex = i;
}
else
- singleNegative = false;
+ singleNegativeIndex = -1;
}
else {
if (firstPositive == null) {
firstPositive = item;
- singlePositive = true;
+ singlePositiveIndex = i;
}
else
- singlePositive = false;
+ singlePositiveIndex = -1;
}
}
else
notifyItemChanged(i + 1);
}
- if (singleNegative) {
+ if (singleNegativeIndex != -1) {
firstNegative.getAccount()
.resetAmount();
+ model.moveItemLast(singleNegativeIndex);
}
- else if (singlePositive) {
+ else if (singlePositiveIndex != -1) {
firstPositive.getAccount()
.resetAmount();
+ model.moveItemLast(singlePositiveIndex);
}
}
model.checkTransactionSubmittable(this);
final MutableLiveData<Boolean> commentVisible = getItem(position).commentVisible;
commentVisible.postValue(!commentVisible.getValue());
}
+ public void moveItemLast(int index) {
+ /* 0
+ 1 <-- index
+ 2
+ 3 <-- desired position
+ */
+ int itemCount = items.size();
+
+ if (index < itemCount - 1) {
+ Item acc = items.remove(index);
+ items.add(itemCount - 1, acc);
+ }
+ }
enum ItemType {generalData, transactionRow, bottomFiller}
//==========================================================================================