previously, when there was a single account with negative amount, that
amount was cleared from the row so that it is filled automatically when
the amounts of other accounts change
now this is also done for the single account with a positive amount if
there is one, and there are multiple accounts with negative amounts
ArrayList<LedgerTransactionAccount> accounts = tr.getAccounts();
NewTransactionModel.Item firstNegative = null;
NewTransactionModel.Item firstPositive = null;
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);
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;
if (acc.getAmount() < 0) {
if (firstNegative == null) {
firstNegative = item;
+ singleNegativeIndex = i;
- singleNegative = false;
+ singleNegativeIndex = -1;
}
else {
if (firstPositive == null) {
firstPositive = item;
}
else {
if (firstPositive == null) {
firstPositive = item;
+ singlePositiveIndex = i;
- singlePositive = false;
+ singlePositiveIndex = -1;
notifyItemChanged(i + 1);
}
notifyItemChanged(i + 1);
}
+ if (singleNegativeIndex != -1) {
firstNegative.getAccount()
.resetAmount();
firstNegative.getAccount()
.resetAmount();
+ model.moveItemLast(singleNegativeIndex);
- else if (singlePositive) {
+ else if (singlePositiveIndex != -1) {
firstPositive.getAccount()
.resetAmount();
firstPositive.getAccount()
.resetAmount();
+ model.moveItemLast(singlePositiveIndex);
}
}
model.checkTransactionSubmittable(this);
}
}
model.checkTransactionSubmittable(this);
final MutableLiveData<Boolean> commentVisible = getItem(position).commentVisible;
commentVisible.postValue(!commentVisible.getValue());
}
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}
//==========================================================================================
enum ItemType {generalData, transactionRow, bottomFiller}
//==========================================================================================