h6ah4i / android-advancedrecyclerview

RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)
https://advancedrecyclerview.h6ah4i.com/
Apache License 2.0
5.32k stars 862 forks source link

Remove parent if all the child items are swiped. #174

Open Amiit-Kkumar opened 8 years ago

Amiit-Kkumar commented 8 years ago

After swiping the last child item I want my parent to be removed from recyclerview , I am deleting the parent from List but its crashing because of notifydatasetchanged, how can I programmatically delete the parent?

Code:

public void onPerformAfterSwipeChildReaction(RecyclerView.ViewHolder holder, int parentPosition, int childPosition, int result, int reaction) {

final long expandablePosition = RecyclerViewExpandableItemManager.getPackedPositionForChild(parentPosition, childPosition);

final int flatPosition = mExpandableItemManager.getFlatPosition(expandablePosition);

    if (reaction == RecyclerViewSwipeManager.AFTER_SWIPE_REACTION_REMOVE_ITEM) {
        if (mEventListener != null) {
            notifyItemRemoved(flatPosition);
            mEventListener.onChildSwipedFromParent(parentPosition, childPosition);
        }

    }
}

And on callback of onChildSwipedFromParent(), I am checking if the child count is 0 for a parent , I am deleting the parent from the list.

h6ah4i commented 8 years ago

Hi. Please check the issue #70, I have posted a sample code which handles the same problem. However the issue #70 is written for a bit old version of this library, so I will port it for the latest version later.