FastAdapter icon indicating copy to clipboard operation
FastAdapter copied to clipboard

SwipeList Sample: After swipe, disable swipe ability

Open echthard opened this issue 9 years ago • 5 comments

The sample does not prevent rows from swiping multiple times, whilst the row is already swiped. It's better to disable swiping when a row has been swiped.

I haven't found an easy solution yet, i.e. setting item.WithEnabled(false) has no noticable change.

When I try to swipe a lot of times on a single row, then sometimes a bug pops up: The colored view stays visible, even when the row has been removed. And it even stays at the same spot when I scroll.

image

echthard avatar Jan 24 '17 19:01 echthard

hi mikepenz, thank you for yours fast adapter, i have some isue when using swipe list sample, i want to call approve function if i swipe to right and call reject function if i swipe to left,iam not clear where to call it. i have try in function itemSwiped but i dont know how to identify left or right. can you help me, thank you iam new on android and java

anton-khansa avatar Feb 12 '17 11:02 anton-khansa

Hi anton-khansa,

In the sample app, in SwipeListActivity.java you will find an override of itemSwiped(). There is a variable called "direction". You can use that.

@Override
public void itemSwiped(int position, int direction) {
}

echthard avatar Feb 12 '17 16:02 echthard

hi echthard, thank you for your response, i want to call this function :

  1. call function approve() if swipe right
  2. call function reject() if swipe left

where should i call that?iam still dont know how to identify left or right, could u help me?really appreciated for your help.below is the function from SwipeListActivity.java.

 @Override
    public void itemSwiped(int position, int direction) {
    
        final SwipeableItem item = fastItemAdapter.getItem(position);
        item.setSwipedDirection(direction);

        final Runnable removeRunnable = new Runnable() {
            @Override
            public void run() {
                item.setSwipedAction(null);
                int position = fastItemAdapter.getAdapterPosition(item);
                if (position != RecyclerView.NO_POSITION) {
                    fastItemAdapter.remove(position);
                }
            }
        };
        final View rv = findViewById(R.id.rv);
        rv.postDelayed(removeRunnable, 3000);

        item.setSwipedAction(new Runnable() {
            @Override
            public void run() {
                rv.removeCallbacks(removeRunnable);
                item.setSwipedDirection(0);
                int position = fastItemAdapter.getAdapterPosition(item);
                if (position != RecyclerView.NO_POSITION) {
                    fastItemAdapter.notifyItemChanged(position);
                }
            }
        });

        fastItemAdapter.notifyItemChanged(position);
    }

anton-khansa avatar Feb 14 '17 13:02 anton-khansa

 @Override
    public void itemSwiped(int position, int direction) {
      
        if (direction == ItemTouchHelper.RIGHT) {
            approve();
        } else if (direction == ItemTouchHelper.LEFT) {
            reject();
        }
       ... // rest what you want to do with it.
    }

echthard avatar Feb 14 '17 16:02 echthard

with v2.1.7 there is now a new ISwipeable interface which allows you to disable swiping on a per-item basis

mikepenz avatar Feb 15 '17 22:02 mikepenz