// Path: channelmanager/src/main/java/com/example/channelmanager/base/ItemDragListener.java
// public interface ItemDragListener {
//     void onItemMove(int fromPosition, int toPosition);
// 
//     void onItemSwiped(int position);
// }
// 
// Path: channelmanager/src/main/java/com/example/channelmanager/base/ItemDragVHListener.java
// public interface ItemDragVHListener {
//     void onItemSelected();
// 
//     void onItemFinished();
// }


import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.helper.ItemTouchHelper;
import com.example.channelmanager.base.ItemDragListener;
import com.example.channelmanager.base.ItemDragVHListener;

    @Override
    public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
        int dragFlags;
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        if (layoutManager instanceof GridLayoutManager || layoutManager instanceof StaggeredGridLayoutManager) {
            dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.START | ItemTouchHelper.END;
        } else {
            dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
        }
        int swipeFlags = 0;
        return makeMovementFlags(dragFlags, swipeFlags);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
        if (source.getItemViewType() != target.getItemViewType())
            return false;
        mDragMoveListener.onItemMove(source.getAdapterPosition(), target.getAdapterPosition());
        return true;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
        mDragMoveListener.onItemSwiped(viewHolder.getAdapterPosition());
    }

    @Override
    public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
        if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
// Path: channelmanager/src/main/java/com/example/channelmanager/base/ItemDragListener.java
// public interface ItemDragListener {
//     void onItemMove(int fromPosition, int toPosition);
// 
//     void onItemSwiped(int position);
// }
// 
// Path: channelmanager/src/main/java/com/example/channelmanager/base/ItemDragVHListener.java
// public interface ItemDragVHListener {
//     void onItemSelected();
// 
//     void onItemFinished();
// }


// Path: channelmanager/src/main/java/com/example/channelmanager/ItemDragHelperCallback.java
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.helper.ItemTouchHelper;
import com.example.channelmanager.base.ItemDragListener;
import com.example.channelmanager.base.ItemDragVHListener;


    @Override
    public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
        int dragFlags;
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        if (layoutManager instanceof GridLayoutManager || layoutManager instanceof StaggeredGridLayoutManager) {
            dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.START | ItemTouchHelper.END;
        } else {
            dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
        }
        int swipeFlags = 0;
        return makeMovementFlags(dragFlags, swipeFlags);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
        if (source.getItemViewType() != target.getItemViewType())
            return false;
        mDragMoveListener.onItemMove(source.getAdapterPosition(), target.getAdapterPosition());
        return true;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
        mDragMoveListener.onItemSwiped(viewHolder.getAdapterPosition());
    }

    @Override
    public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
        if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
            ItemDragVHListener itemViewHolder = (ItemDragVHListener) viewHolder;