public int getMovementFlags(@NonNull RecyclerView recyclerView,
@NonNull RecyclerView.ViewHolder viewHolder) {
int flags = makeFlag(ItemTouchHelper.ACTION_STATE_IDLE, ItemTouchHelper.END);
- if (viewModel.getAccountCount() > 2) flags |=
- makeFlag(ItemTouchHelper.ACTION_STATE_SWIPE,
+ // the top item is always there (date and description)
+ if (viewHolder.getAdapterPosition() > 0) {
+ if (viewModel.getAccountCount() > 2) {
+ flags |= makeFlag(ItemTouchHelper.ACTION_STATE_SWIPE,
ItemTouchHelper.START | ItemTouchHelper.END);
+ }
+ }
+
return flags;
}
@Override
Snackbar.LENGTH_LONG).setAction("Action", null).show();
else {
int pos = viewHolder.getAdapterPosition();
- listAdapter.removeItem(pos);
- // FIXME hook next/prev links somehow
- throw new RuntimeException("TODO");
+ viewModel.removeItem(pos - 1);
+ listAdapter.notifyItemRemoved(pos);
+ viewModel.sendCountNotifications(); // needed after items re-arrangement
+ viewModel.checkTransactionSubmittable(listAdapter);
}
}
}).attachToRecyclerView(list);
String.format(Locale.US, "invoking notifyItemInserted(%d)", newAccountCount));
// the header is at position 0
notifyItemInserted(newAccountCount);
+ model.sendCountNotifications(); // needed after holders' positions have changed
return newAccountCount;
}
@NonNull
if (presentItemCount > 2)
notifyItemRangeRemoved(3, presentItemCount - 2); // all the rest are gone
}
- public void removeItem(int pos) {
- model.removeItem(pos - 1, this);
- notifyItemRemoved(pos);
- }
}
isSubmittable.setValue(false);
}
}
- public void removeItem(int pos, NewTransactionItemsAdapter adapter) {
+ public void removeItem(int pos) {
items.remove(pos);
accountCount.setValue(getAccountCount());
- checkTransactionSubmittable(adapter);
+ }
+ public void sendCountNotifications() {
+ accountCount.setValue(getAccountCount());
}
enum ItemType {generalData, transactionRow, bottomFiller}