package com.oasisfeng.android.databinding.adapters;

import android.databinding.BindingAdapter;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.SwipeDismissBehavior;
import android.view.View;

/**
 * Binding adapter to attach {@link SwipeDismissBehavior} to any view inside {@link CoordinatorLayout}.
 *
 * Created by Oasis on 2017/9/9.
 */
public class SwipeDismissBehaviorBindingAdapter {

	@BindingAdapter(value = {"swipeDismissible", "dragDismissDistance"}, requireAll = false)
	public static void setSwipeDismissBehavior(final View view, final boolean dismissible, final @Nullable Float drag_dismiss_distance) {
		final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams();
		final CoordinatorLayout.Behavior behavior = params.getBehavior();
		if (! dismissible) {
			if (behavior instanceof SwipeDismissBehavior) params.setBehavior(null);
			return;
		}
		final SwipeDismissBehavior<?> swipe_behavior = behavior instanceof SwipeDismissBehavior ? (SwipeDismissBehavior) behavior
				: new SwipeDismissBehavior<>();
		swipe_behavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_ANY);
		if (drag_dismiss_distance != null) swipe_behavior.setDragDismissDistance(drag_dismiss_distance);
		swipe_behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {

			@Override public void onDismiss(final View view) {
				view.setVisibility(View.GONE);
				view.setAlpha(1);		// Reset the alpha after fade-out for possible later reuse of the card view.
			}

			@Override public void onDragStateChanged(final int state) {}
		});
		params.setBehavior(swipe_behavior);
	}
}

@@ -541,16 +541,29 @@
 istance%22
+, %22onDismiss%22
 %7D, requi
@@ -708,16 +708,63 @@
 distance
+,%0A%09%09%09%09%09%09%09%09%09%09%09   final Runnable dismiss_callback
 ) %7B%0A%09%09fi
@@ -1648,16 +1648,74 @@
 d view.%0A
+%09%09%09%09if (dismiss_callback != null) dismiss_callback.run();%0A
 %09%09%09%7D%0A%0A%09%09

Add "onDismiss" callback attribute to SwipeDismissBehaviorBindingAdapter.