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 860 forks source link

Swipeable RecyclerView Tutorial #207

Open ivandamyanov opened 8 years ago

ivandamyanov commented 8 years ago

I think one of the most attractive things about this library is the swipeable feature with icons below the RecyclerView item allowing to take action, as we've seen them on Google apps. I have never seen a tutorial online on this library and it is really hard to implement its features.

Does anyone know of a tutorial on the Swipeable features? I tried following the guide that the author wrote but it lead me nowhere. I really need this feature and the library seems to be doing great in the demo video, but obviously no one implements it and helps other do it too. I'd really like it if someone could make an example how to implement that with at least it's basic working functionality. Thank you

h6ah4i commented 8 years ago

Hi. Have you took a look at my examples code? The "Swipeable (basic)" example shows how to implement Google's Inbox app like behavior. Thanks.


How to change item background

  1. Implement onSetSwipeBackground() method

    :point_right: SwipeableExampleAdapter.java#L171

  2. Use SwipeDismissItemAnimator (optional, but required to improve dismiss animation)

    :point_right: SwipeableExampleFragment.java#L97


Support item pinning

  1. Add isPinned state to each item data, and also its getter and setter

    :point_right: ExampleDataProvider.java#L150

  2. Update onBindItemView() method

    holder.setSwipeItemHorizontalSlideAmount(
           item.isPinned() ? Swipeable.OUTSIDE_OF_THE_WINDOW_LEFT : 0);

    :point_right: SwipeableExampleAdapter.java#L156

  3. Implement your Swipe**ResultAction class which extends SwipeResultActionMoveToSwipedDirection

    Set isPinned = true inside of the onPerformAction() method.

    :point_right: SwipeableExampleAdapter.java#L224

  4. Return an instance of the Swipe**ResultAction class inside of the onSwipeItem()

    :point_right: SwipeableExampleAdapter.java#L204


How to implement click event

A. If item is not pinned.

Click event will be fired on the view which is returned from SwipeableItemViewHolder.getSwipeableContainerView().

:point_right: SwipeableExampleAdapter.java#L133

B. If item is pinned.

Click event will be fired on the ViewHolder.itemView.

:point_right: SwipeableExampleAdapter.java#L131