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.R;
import com.example.beijing_daxing.been.Stock;
import com.example.beijing_daxing.databinding.ItemOutBinding;
import com.example.beijing_daxing.databinding.ItemStoreCheckBinding;

import java.util.List;

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

    public OutAdapter(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) {
        ItemOutBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_out, 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 ItemOutBinding binding;

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

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