package com.sound.prankparty.Utils;

import android.content.Context;
import android.graphics.Canvas;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.sound.prankparty.Fragment.RadioFragment;
import com.sound.prankparty.R;

public class MyItemTouchHelperCallback extends ItemTouchHelper.SimpleCallback {

    private RadioFragment radioFragment;

    // 构造方法，初始化回调对象
    public MyItemTouchHelperCallback(RadioFragment fragment) {
        super(0, ItemTouchHelper.LEFT); // 只允许左滑
        this.radioFragment = fragment;
    }

    // 处理移动事件的方法，这里不处理移动事件
    @Override
    public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
        return false; // 不处理移动事件
    }

    // 处理滑动事件的方法
    @Override
    public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
        // 当滑动项被完全滑出时，执行相应操作，比如删除或编辑
        int position = viewHolder.getAdapterPosition();
        radioFragment.deleteItem(position);
    }
}

