]> git.ktnx.net Git - mobile-ledger-staging.git/commitdiff
NT: correctly disable swiping of top and bottom entries, let all the rest be swiped
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 14 Mar 2020 19:25:30 +0000 (21:25 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 14 Mar 2020 19:25:30 +0000 (21:25 +0200)
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

app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java

index c9b9230e1235891ff0e018e1fe3a2cd32c7a68da..5f2f4c6c4fa653b0a610a0187535a269a8387da1 100644 (file)
@@ -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<NewTransactionItem
             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;
index cad07c0def34ee0ea3acb810775aa98a81c4f270..7c49bf1b4b08a0e49ad9b166ed147367ea7ab894 100644 (file)
@@ -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);