}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
- if (viewModel.getAccountCount() == 2)
- Snackbar.make(recyclerView, R.string.msg_at_least_two_accounts_are_required,
- Snackbar.LENGTH_LONG)
- .setAction("Action", null)
- .show();
- else {
- int pos = viewHolder.getAdapterPosition();
- viewModel.removeItem(pos - 1);
- notifyItemRemoved(pos);
- viewModel.sendCountNotifications(); // needed after items re-arrangement
- viewModel.checkTransactionSubmittable(adapter);
- }
+ int pos = viewHolder.getAdapterPosition();
+ viewModel.removeItem(pos - 1);
+ notifyItemRemoved(pos);
+ viewModel.sendCountNotifications(); // needed after items re-arrangement
+ viewModel.checkTransactionSubmittable(adapter);
}
});
}
tr = profile.loadTransaction(transactionId);
ArrayList<LedgerTransactionAccount> accounts = tr.getAccounts();
NewTransactionModel.Item firstNegative = null;
- boolean singleNegative = false;
+ NewTransactionModel.Item firstPositive = null;
+ 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
+ singleNegativeIndex = -1;
+ }
+ else {
+ if (firstPositive == null) {
+ firstPositive = item;
+ singlePositiveIndex = i;
}
else
- singleNegative = false;
+ singlePositiveIndex = -1;
}
}
else
notifyItemChanged(i + 1);
}
- if (singleNegative) {
+ if (singleNegativeIndex != -1) {
firstNegative.getAccount()
.resetAmount();
+ model.moveItemLast(singleNegativeIndex);
+ }
+ else if (singlePositiveIndex != -1) {
+ firstPositive.getAccount()
+ .resetAmount();
+ model.moveItemLast(singlePositiveIndex);
}
}
model.checkTransactionSubmittable(this);