text: package com.ogulcan.android.mvp.app.util
  
  import android.content.Context
  import android.graphics.Canvas
  import android.graphics.Color
  import android.graphics.drawable.ColorDrawable
  import android.support.v4.content.ContextCompat
  import android.support.v7.widget.RecyclerView
  import android.support.v7.widget.helper.ItemTouchHelper
  import com.ogulcan.android.mvp.app.R
  
  /**
   * Created by ogulcan on 08/02/2018.
   */
  abstract class SwipeToDelete(context: Context): ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
  
      private val deleteIcon = ContextCompat.getDrawable(context, R.drawable.ic_delete24)
      private val intrinsicWidth = deleteIcon.intrinsicWidth
      private val intrinsicHeight = deleteIcon.intrinsicHeight
  
      override fun onMove(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder?, target: RecyclerView.ViewHolder?): Boolean {
          return false
          // No need to implement drag & drop
      }
  
      override fun onChildDraw(c: Canvas?, recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder?, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) {
          val itemView = viewHolder!!.itemView
          val itemHeight = itemView.bottom - itemView.top
  
          val background = ColorDrawable()
          background.color = Color.parseColor("#801515")
          background.setBounds(itemView.right + dX.toInt(), itemView.top, itemView.right, itemView.bottom)
          background.draw(c)
  
          val deleteIconTop = itemView.top + (itemHeight - intrinsicHeight) / 2
          val deleteIconMargin = (itemHeight - intrinsicHeight) / 2
          val deleteIconLeft = itemView.right - deleteIconMargin - intrinsicWidth
          val deleteIconRight = itemView.right - deleteIconMargin
          val deleteIconBottom = deleteIconTop + intrinsicHeight
  
          deleteIcon.setBounds(deleteIconLeft, deleteIconTop, deleteIconRight, deleteIconBottom)
          deleteIcon.draw(c)
  
          super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
      }
  }