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 PatrolPointAdapter extends RecyclerView.Adapter<PatrolPointAdapter.ViewHolder> {
    private List<PatrolPoint> list;
    private Context mContext;
    private onRecyclerViewItemClick mOnRvItemClick;

    public PatrolPointAdapter(Context mContext,List<PatrolPoint> 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_patrolpoint,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) {
        PatrolPoint patrolPoint = list.get(position);
        holder.tv_point.setText(patrolPoint.getName());
    }

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

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        View point;
        TextView tv_point;
        public ViewHolder(View itemView) {
            super(itemView);
            point = itemView;
            tv_point = (TextView) itemView.findViewById(R.id.item_patrolpoint_tv_name);
            point.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);
    }

}
