content: package com.akansh.fileserversuit;
  
  import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.graphics.PorterDuff;
  import android.graphics.PorterDuffXfermode;
  import android.graphics.drawable.ColorDrawable;
  import android.graphics.drawable.Drawable;
  import android.view.View;
  
  import androidx.annotation.NonNull;
  import androidx.core.content.ContextCompat;
  import androidx.recyclerview.widget.ItemTouchHelper;
  import androidx.recyclerview.widget.RecyclerView;
  
  abstract public class SwipeDeleteCallback extends ItemTouchHelper.Callback {
  
      Context mContext;
      private final Paint mClearPaint;
      private final ColorDrawable mBackground;
      private final int backgroundColor;
      private final Drawable deleteDrawable;
      private final int intrinsicWidth;
      private final int intrinsicHeight;
  
  
      SwipeDeleteCallback(Context context) {
          mContext = context;
          mBackground = new ColorDrawable();
          backgroundColor = Color.parseColor("#FFFF1414");
          mClearPaint = new Paint();
          mClearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
          deleteDrawable = ContextCompat.getDrawable(mContext, R.drawable.ic_delete_swipe);
          intrinsicWidth = deleteDrawable.getIntrinsicWidth();
          intrinsicHeight = deleteDrawable.getIntrinsicHeight();
      }
  
  
      @Override
      public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
          return makeMovementFlags(0, ItemTouchHelper.RIGHT);
      }
  
      @Override
      public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder viewHolder1) {
          return false;
      }
  
      @Override
      public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
          super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
  
          View itemView = viewHolder.itemView;
          int itemHeight = itemView.getHeight();
  
          boolean isCancelled = dX == 0 && !isCurrentlyActive;
  
          if (isCancelled) {
              clearCanvas(c, itemView.getRight() + dX, (float) itemView.getTop(), (float) itemView.getRight(), (float) itemView.getBottom());
              super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
              return;
          }
  
          mBackground.setColor(backgroundColor);
          mBackground.setBounds(itemView.getLeft() + (int) dX, itemView.getTop(), itemView.getLeft(), itemView.getBottom());
          mBackground.draw(c);
  
          int deleteIconTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2;
          int deleteIconMargin = (itemHeight - intrinsicHeight) / 2;
  
          int deleteIconLeft =  deleteIconMargin - intrinsicWidth;
          int deleteIconRight =  deleteIconMargin;
  
          int deleteIconBottom = deleteIconTop + intrinsicHeight;
  
  
          deleteDrawable.setBounds(deleteIconLeft, deleteIconTop, deleteIconRight, deleteIconBottom);
          deleteDrawable.draw(c);
  
          super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
  
  
      }
  
      private void clearCanvas(Canvas c, Float left, Float top, Float right, Float bottom) {
          c.drawRect(left, top, right, bottom, mClearPaint);
  
      }
  
      @Override
      public float getSwipeThreshold(@NonNull RecyclerView.ViewHolder viewHolder) {
          return 0.7f;
      }
  }
  
  