package com.sipai.jspatrol.NFC;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;

import com.sipai.jspatrol.R;

import java.util.List;

/**
 * Created by lvliming on 2019/5/7.
 */

public class EquNFCAdapter extends RecyclerView.Adapter<EquNFCAdapter.ViewHolder> {
    private List<EquList> list;
    private Context mContext;
    private onRecyclerViewItemClick mOnRvItemClick;

    public EquNFCAdapter(Context mContext, List<EquList> list, onRecyclerViewItemClick mOnRvItemClick) {
        this.mContext = mContext;
        this.list = list;
        this.mOnRvItemClick = mOnRvItemClick;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_equ_nfc,parent,false);
        final ViewHolder holder = new ViewHolder(view);
//        holder.point.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                int position = holder.getAdapterPosition();
//                PatrolPoint patrolPoint = list.get(position);
//                WriteTag.actionStart(view.getContext(),patrolPoint.getId());
//            }
//        });
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        EquList equ = list.get(position);
        holder.tv_equ_name.setText(equ.getEquipmentname());
        holder.tv_equ_info.setText("设备编号："+equ.getEquipmentcardid()+"\n"+"资产编号："+equ.getAssetnumber());
    }

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

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        View equ;
        TextView tv_equ_name,tv_equ_info;
        public ViewHolder(View itemView) {
            super(itemView);
            equ = itemView;
            tv_equ_name = (TextView) itemView.findViewById(R.id.moudle_equ_nfc_tv_name);
            tv_equ_info = itemView.findViewById(R.id.moudle_equ_nfc_tv_info);
            equ.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            if (mOnRvItemClick != null)
                mOnRvItemClick.onItemClick(view, getAdapterPosition());
        }
    }
    /**
     * item点击接口
     */
    public interface onRecyclerViewItemClick {
        void onItemClick(View v, int position);
    }

}
