package com.example.beijing_daxing.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.example.beijing_daxing.BR;
import com.example.beijing_daxing.R;
import com.example.beijing_daxing.base.AdapterClickCall;
import com.example.beijing_daxing.been.Stock;
import com.example.beijing_daxing.databinding.ItemCheckBinding;
import com.example.beijing_daxing.databinding.ItemStoreCheckBinding;

import java.util.List;

/**
 * @author wanghao
 * @date 2024/1/19  14:32
 */
public class CheckAdapter extends RecyclerView.Adapter<CheckAdapter.MyViewHoder> {
    private Context context;
    private List<Stock> list;
    private LayoutInflater inflater;
    private AdapterClickCall call;
    public CheckAdapter(Context context,AdapterClickCall call) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.call=call;
    }

    public void setList(List<Stock> list) {
        this.list = list;
    }

    @Override
    public MyViewHoder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemCheckBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_check, parent, false);
        return new MyViewHoder(binding);
    }

    @Override
    public void onBindViewHolder(MyViewHoder holder, int position) {
        var binding = holder.getBinding();
        binding.setVariable(BR.item,list.get(position));
        binding.itemCheckClick.setOnClickListener(v ->  call.clickItem(position));
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    public class MyViewHoder extends RecyclerView.ViewHolder {
        private ItemCheckBinding binding;

        public MyViewHoder( ItemCheckBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

        public ItemCheckBinding getBinding() {
            return binding;
        }
    }
}
