From: Damyan Ivanov Date: Sat, 14 Mar 2020 19:25:30 +0000 (+0200) Subject: NT: correctly disable swiping of top and bottom entries, let all the rest be swiped X-Git-Tag: v0.12.0~68 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=040d5ba3aaa78a295a6c4a29500a234d3188ad6b NT: correctly disable swiping of top and bottom entries, let all the rest be swiped top is the entry with the date/description; bottom is the padding all the rest can be swiped and the call to checkTransactionSubmittable() will make sure that there are at least two account rows present --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java index c9b9230e..5f2f4c6c 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java @@ -26,8 +26,6 @@ import androidx.annotation.NonNull; 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; @@ -84,15 +82,13 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter 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; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java index cad07c0d..7c49bf1b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java @@ -153,6 +153,8 @@ public class NewTransactionModel extends ViewModel { 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) { @@ -258,6 +260,9 @@ public class NewTransactionModel extends ViewModel { 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);