package com.cooleshow.student.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.student.R;
import com.cooleshow.student.bean.PracticeVideoWorkBean;

import java.util.List;

/**
 * 创建日期：2022/5/31 14:39
 *
 * @author Ryan
 * 类说明：
 */
public class PracticeVideoWorkAdapter extends BaseMultiItemQuickAdapter<PracticeVideoWorkBean, BaseViewHolder> {
    public PracticeVideoWorkAdapter(List<PracticeVideoWorkBean> data) {
        super(data);
        addItemType(0, R.layout.item_practice_video_layout);
        addItemType(1, R.layout.item_practice_video_layout_add);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, PracticeVideoWorkBean styleVideoBean) {
        switch (styleVideoBean.getItemType()) {
            case 0:
                //加载视频缩略图
                ImageView iv_video_bg = holder.getView(R.id.iv_video_bg);
                ImageView iv_del = holder.getView(R.id.iv_del);
                GlideUtils.INSTANCE.loadVideoThumbnail(getContext(), styleVideoBean.videoUrl, iv_video_bg);
                iv_video_bg.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (itemAddClickAction != null) {
                            itemAddClickAction.previewVideo(styleVideoBean.videoUrl);
                        }
                    }
                });
                iv_del.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (itemAddClickAction != null) {
                            itemAddClickAction.delVideo(holder.getLayoutPosition());
                        }
                    }
                });
                iv_del.setVisibility(styleVideoBean.status == 0 ? View.VISIBLE : View.INVISIBLE);
                break;
            case 1:
                ImageView iv_video_add = holder.getView(R.id.iv_video_add);
                iv_video_add.setOnClickListener(view -> {
                    if (null != itemAddClickAction) {
                        itemAddClickAction.add();
                    }
                });
                break;

        }
    }

    private ItemAddClickAction itemAddClickAction;

    public void setItemAddClickAction(ItemAddClickAction itemAddClickAction) {
        this.itemAddClickAction = itemAddClickAction;

    }

    public interface ItemAddClickAction {
        void add();

        void previewVideo(String url);

        void delVideo(int pos);
    }
}
