import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
-import com.google.android.material.snackbar.Snackbar;
-
import net.ktnx.mobileledger.App;
import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.async.DescriptionSelectedCallback;
public int getMovementFlags(@NonNull RecyclerView recyclerView,
@NonNull RecyclerView.ViewHolder viewHolder) {
int flags = makeFlag(ItemTouchHelper.ACTION_STATE_IDLE, ItemTouchHelper.END);
- // the top item is always there (date and description)
- if (viewHolder.getAdapterPosition() > 0) {
+ // the top (date and description) and the bottom (padding) items are always there
+ final int adapterPosition = viewHolder.getAdapterPosition();
+ if ((adapterPosition > 0) && (adapterPosition < adapter.getItemCount() - 1)) {
flags |= makeFlag(ItemTouchHelper.ACTION_STATE_DRAG,
- ItemTouchHelper.UP | ItemTouchHelper.DOWN);
-
- if (viewModel.getAccountCount() > 2) {
- flags |= makeFlag(ItemTouchHelper.ACTION_STATE_SWIPE,
- ItemTouchHelper.START | ItemTouchHelper.END);
- }
+ ItemTouchHelper.UP | ItemTouchHelper.DOWN) |
+ makeFlag(ItemTouchHelper.ACTION_STATE_SWIPE,
+ ItemTouchHelper.START | ItemTouchHelper.END);
}
return flags;
3a) there must be exactly one empty amount (with account)
4) empty accounts with empty amounts are ignored
5) a row with an empty account name or empty amount is guaranteed to exist
+ 6) at least two rows need to be present in the ledger
+
*/
@SuppressLint("DefaultLocale")
public void checkTransactionSubmittable(NewTransactionItemsAdapter adapter) {
adapter.addRow();
}
+ // 6) at least two rows need to be present in the ledger
+ while (this.items.size() < 2) adapter.addRow();
+
debug("submittable", submittable ? "YES" : "NO");
isSubmittable.setValue(submittable);