use of com.google.android.material.behavior.SwipeDismissBehavior.OnDismissListener in project ods-android by Orange-OpenSource.
the class CardSwipeDismissFragment method onCreateDemoView.
/**
* Inflate fragment view and setup with {@link SwipeDismissBehavior}
*/
@Override
public View onCreateDemoView(LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
View view = layoutInflater.inflate(R.layout.cat_card_swipe_fragment, viewGroup, false);
CoordinatorLayout container = view.findViewById(R.id.card_container);
SwipeDismissBehavior<View> swipeDismissBehavior = new SwipeDismissBehavior<>();
swipeDismissBehavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
MaterialCardView cardContentLayout = view.findViewById(R.id.card_content_layout);
CoordinatorLayout.LayoutParams coordinatorParams = (CoordinatorLayout.LayoutParams) cardContentLayout.getLayoutParams();
coordinatorParams.setBehavior(swipeDismissBehavior);
swipeDismissBehavior.setListener(new OnDismissListener() {
@Override
public void onDismiss(View view) {
Snackbar.make(container, R.string.cat_card_dismissed, Snackbar.LENGTH_INDEFINITE).setAction(R.string.cat_card_undo, v -> resetCard(cardContentLayout)).show();
}
@Override
public void onDragStateChanged(int state) {
CardSwipeDismissFragment.onDragStateChanged(state, cardContentLayout);
}
});
return view;
}
Aggregations