@Override
  public void onDestroyView() {
    if (mRecyclerViewDragDropManager != null) {
      mRecyclerViewDragDropManager.release();
      mRecyclerViewDragDropManager = null;
    }

    if (mRecyclerViewSwipeManager != null) {
      mRecyclerViewSwipeManager.release();
      mRecyclerViewSwipeManager = null;
    }

    if (mRecyclerViewTouchActionGuardManager != null) {
      mRecyclerViewTouchActionGuardManager.release();
      mRecyclerViewTouchActionGuardManager = null;
    }

    if (mRecyclerView != null) {
      mRecyclerView.setItemAnimator(null);
      mRecyclerView.setAdapter(null);
      mRecyclerView = null;
    }

    if (mWrappedAdapter != null) {
      WrapperAdapterUtils.releaseAll(mWrappedAdapter);
      mWrappedAdapter = null;
    }
    //        mSetlistAdapter = null;
    mLayoutManager = null;

    super.onDestroyView();
  }
  @Override
  public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mLayoutManager = new LinearLayoutManager(getActivity());

    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss
    // animation is running)
    mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
    mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);

    // drag and drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setSwapTargetTranslationInterpolator(
        new BasicSwapTargetTranslationInterpolator());
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
        (NinePatchDrawable) getResources().getDrawable(R.drawable.material_shadow_z1));

    // swipe manager
    mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();

    // adapter
    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(getAdapter());
    mWrappedAdapter =
        mRecyclerViewSwipeManager.createWrappedAdapter(mWrappedAdapter); // wrap for swiping

    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter); // required *wrapped adapter*
    mRecyclerView.setItemAnimator(new RefactoredDefaultItemAnimator());

    // additional decorations
    if (!supportsViewElevation()) {
      // for pre-lollipop
      mRecyclerView.addItemDecoration(
          new ItemShadowDecorator(
              (NinePatchDrawable) getResources().getDrawable(R.drawable.material_shadow_z1)));
    }
    mRecyclerView.addItemDecoration(
        new SimpleListDividerDecorator(getResources().getDrawable(R.drawable.list_divider), true));

    // NOTE:
    // The initialization order is very important! This order determines the priority of touch event
    // handling.
    //
    // priority: TouchActionGuard > Swipe > DragAndDrop
    mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);
  }
 @Override
 public void onPause() {
   mRecyclerViewDragDropManager.cancelDrag();
   super.onPause();
 }