From: Damyan Ivanov Date: Sun, 10 Nov 2019 17:44:16 +0000 (+0200) Subject: fix swipe-away in reworked new transaction activity X-Git-Tag: v0.11.0~86 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=d4e592c5aed998f3b3e5afcf2150fb051aaf3e6f;ds=sidebyside fix swipe-away in reworked new transaction activity the first item (date and description) can't be swiped, as well as the last two remaining accounts --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java index 950bce32..4e6ee192 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java @@ -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); 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 1585f1d8..91c6d311 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 @@ -64,6 +64,7 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter 2) notifyItemRangeRemoved(3, presentItemCount - 2); // all the rest are gone } - public void removeItem(int pos) { - model.removeItem(pos - 1, this); - notifyItemRemoved(pos); - } } 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 330b5ac2..f6ecb443 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 @@ -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}