package com.sjkj.base_lib.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.sjkj.base_lib.R;
import com.sjkj.base_lib.databinding.ItemImageDelListBinding;
import com.sjkj.base_lib.entity.ImageBean;
import com.sjkj.base_lib.utils.AppTools;

import java.util.List;

public class ImageDelAdapter extends BaseRecAdapter<ImageBean, ItemImageDelListBinding> {
    private OnDeleteClick onDeleteClick;

    public ImageDelAdapter(Context context) {
        super(context);
    }

    public ImageDelAdapter(Context context, List<ImageBean> list) {
        super(context, list);
    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_image_del_list;
    }

    /**
     * 设置列表的点击事件回调接口
     */
    public  void setOnDeleteClick(OnDeleteClick onDeleteClick) {
        this.onDeleteClick = onDeleteClick;
    }

    @Override
    protected void onBindItem(ItemImageDelListBinding binding, ImageBean bean, int position) {
        binding.setModel(bean);
        binding.executePendingBindings();
        if (AppTools.isGhb()) {
            binding.rlImage.setLayoutParams(new RelativeLayout.LayoutParams(300, 300));
            ViewGroup.LayoutParams params = binding.ivIcon.getLayoutParams();
            params.height = 280;
            params.width = 280;
            binding.ivIcon.setLayoutParams(params);
            ViewGroup.LayoutParams params_del = binding.deleteIv.getLayoutParams();
            params_del.height = 75;
            params_del.width = 75;
            binding.deleteIv.setLayoutParams(params_del);
        }
//        binding.titleTv TODO
        if (isEdit) {
            binding.deleteIv.setVisibility(View.VISIBLE);
        } else {
            binding.deleteIv.setVisibility(View.GONE);
        }
        binding.deleteIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (list != null && list.size() > 0) {
                    list.remove(position);
                    notifyDataSetChanged();
                }
                if (onDeleteClick != null) {
                    onDeleteClick.delete(bean, position);
                }
            }
        });
    }


    public interface OnDeleteClick {
        void delete(ImageBean bean, int position);
    }



}
