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.base.AdapterClickCall;
import com.example.beijing_daxing.databinding.ItemInBinding;

import java.util.List;

/**
 * @author wanghao
 * @date 2024/1/16  15:26
 */
public class InAdapter extends RecyclerView.Adapter<InAdapter.MyViewHolder> {
    private List<String> list;
    private Context context;
    private LayoutInflater inflater;
    private AdapterClickCall adapterClickCall;
    public InAdapter(Context context) {
        this.context = context;
        inflater=LayoutInflater.from(context);
    }

    public void setAdapterClickCall(AdapterClickCall adapterClickCall) {
        this.adapterClickCall = adapterClickCall;
    }

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

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemInBinding binding= DataBindingUtil.inflate(inflater, R.layout.item_in,parent,false);
        return new MyViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        String epc=list.get(position);
        ItemInBinding binding = holder.getBinding();
        binding.setEpc(epc);
        binding.setIndex(String.valueOf(position+1));
        binding.itemButtom.setOnClickListener(v -> {
            adapterClickCall.clickItem(position);
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private  ItemInBinding binding;

        public MyViewHolder( ItemInBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

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