package com.example.beijing_daxing.adapter;

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

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

import com.example.beijing_daxing.R;
import com.example.beijing_daxing.been.Stock;
import com.example.beijing_daxing.databinding.ItemStoreCheckBinding;

import java.util.List;

/**
 * @author wanghao
 * @date 2024/1/19  14:32
 */
public class StoreCheckAdapter extends RecyclerView.Adapter<StoreCheckAdapter.MyViewHoder> {
    private Context context;
    private List<Stock> list;
    private LayoutInflater inflater;

    public StoreCheckAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

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

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

    @Override
    public void onBindViewHolder(MyViewHoder holder, int position) {
        var binding = holder.getBinding();
        binding.setItem(list.get(position));

    }

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

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

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

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