Last active
January 27, 2018 08:05
-
-
Save chetdeva/f78efabccdee28e02d21e8b7b6ad877f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Bind ItemTouchHelper.SimpleCallback with RecyclerView | |
* | |
* @param recyclerView RecyclerView to bind to SwipeItemTouchHelperCallback | |
* @param swipeEnabled enable/disable swipe | |
* @param drawableSwipeLeft drawable shown when swiped left | |
* @param drawableSwipeRight drawable shown when swiped right | |
* @param bgColorSwipeLeft background color when swiped left | |
* @param bgColorSwipeRight background color when swiped right | |
* @param onItemSwipeLeft OnItemSwipeListener for swiped left | |
* @param onItemSwipeRight OnItemSwipeListener for swiped right | |
*/ | |
@android.databinding.BindingAdapter(value = {"swipeEnabled", "drawableSwipeLeft", "drawableSwipeRight", "bgColorSwipeLeft", "bgColorSwipeRight", "onItemSwipeLeft", "onItemSwipeRight"}, requireAll = false) | |
public static void setItemSwipeToRecyclerView(RecyclerView recyclerView, boolean swipeEnabled, Drawable drawableSwipeLeft, Drawable drawableSwipeRight, int bgColorSwipeLeft, int bgColorSwipeRight, | |
SwipeItemTouchHelperCallback.OnItemSwipeListener onItemSwipeLeft, SwipeItemTouchHelperCallback.OnItemSwipeListener onItemSwipeRight) { | |
ItemTouchHelper.Callback swipeCallback = new SwipeItemTouchHelperCallback | |
.Builder(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) | |
.bgColorSwipeLeft(bgColorSwipeLeft) | |
.bgColorSwipeRight(bgColorSwipeRight) | |
.drawableSwipeLeft(drawableSwipeLeft) | |
.drawableSwipeRight(drawableSwipeRight) | |
.setSwipeEnabled(swipeEnabled) | |
.onItemSwipeLeftListener(onItemSwipeLeft) | |
.onItemSwipeRightListener(onItemSwipeRight) | |
.build(); | |
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(swipeCallback); | |
itemTouchHelper.attachToRecyclerView(recyclerView); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment