package com.kdanmobile.reader.thumb

import android.support.v7.widget.RecyclerView
import android.support.v7.widget.helper.ItemTouchHelper


class ItemTouchHelpCallback (private val itemMoveSwipeListener: ItemMoveSwipeListener) : ItemTouchHelper.Callback() {

    override fun isLongPressDragEnabled(): Boolean {
        return itemMoveSwipeListener.isLongPressDragEnabled()
    }

    override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
        return itemMoveSwipeListener.getMovementFlags(recyclerView,viewHolder)
    }

    override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
        return itemMoveSwipeListener.onItemMove(viewHolder.adapterPosition, target.adapterPosition)
    }
    override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
        itemMoveSwipeListener.onItemSwipe(viewHolder.adapterPosition)
    }

    override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
        itemMoveSwipeListener.clearView(recyclerView,viewHolder)
        super.clearView(recyclerView, viewHolder)
    }

    override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
        itemMoveSwipeListener.onSelectedChanged(viewHolder, actionState)
        super.onSelectedChanged(viewHolder, actionState)
    }

}