]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix swipe-away in reworked new transaction activity
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 10 Nov 2019 17:44:16 +0000 (19:44 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 10 Nov 2019 17:45:13 +0000 (19:45 +0200)
the first item (date and description) can't be swiped, as well as the last
two remaining accounts

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

index 950bce32d3c0cae9cce25aa6d139436d1c5c2d97..4e6ee19274a795d07100e6ead83c991579d87753 100644 (file)
@@ -91,9 +91,14 @@ public class NewTransactionActivity extends ProfileThemedActivity implements Tas
             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
@@ -109,9 +114,10 @@ public class NewTransactionActivity extends ProfileThemedActivity implements Tas
                             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);
index 1585f1d8d48bde6c1cbb85f0ce04b93f3fb9373b..91c6d311dfe2afe98f2cda88690c0fe5a51eaa2a 100644 (file)
@@ -64,6 +64,7 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
                 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
@@ -177,8 +178,4 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
         if (presentItemCount > 2)
             notifyItemRangeRemoved(3, presentItemCount - 2); // all the rest are gone
     }
-    public void removeItem(int pos) {
-        model.removeItem(pos - 1, this);
-        notifyItemRemoved(pos);
-    }
 }
index 330b5ac26731be52495d5da9d30ce05787dc6601..f6ecb443f49fe775413d50b9df536fe0dedd352f 100644 (file)
@@ -207,10 +207,12 @@ public class NewTransactionModel extends ViewModel {
             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}