package com.sipai.jspatrol.Fault;

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.Bean.EquList;
import com.sipai.jspatrol.R;

import java.util.List;

/**
 * Created by lvliming on 2018/7/22.
 */

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

    public EquSingleChoiceAdapter(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_single_choice,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        EquList equ = list.get(position);
        if (equ.getEquipmentmanufacturer()!=null&&!equ.getEquipmentmanufacturer().isEmpty()) {
            holder.tv_manufacturer.setText(equ.getEquipmentmanufacturer());
        }else {
            holder.tv_manufacturer.setText("厂商暂未录入");
        }
        holder.tv_equipmentStatusManagement.setText(equ.getEquipmentStatusManagement());
        if (equ.getEquipmentStatusManagement().equals("在用")){
            holder.tv_equipmentStatusManagement.setBackground(mContext.getResources().getDrawable(R.drawable.bg_layout_shape_green));
            holder.tv_equipmentStatusManagement.setTextColor(mContext.getResources().getColor(R.color.green06));
        }else {
            holder.tv_equipmentStatusManagement.setBackground(mContext.getResources().getDrawable(R.drawable.bg_layout_shape_gray));
            holder.tv_equipmentStatusManagement.setTextColor(mContext.getResources().getColor(R.color.gray));
        }
        holder.tv_equipmentClass.setText(equ.getEquipmentClass());
        holder.tv_model.setText(equ.getEquipmentmodel());
        holder.tv_equipmentLevel.setText(equ.getEquipmentLevel());
        holder.tv_name.setText(equ.getEquipmentname());
        holder.tv_cardid.setText(equ.getEquipmentcardid());
        holder.tv_ps.setText(equ.getProcessSection());
        holder.tv_model.setText(equ.getEquipmentTypeNumber());
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        View tview;
        TextView tv_manufacturer,tv_name,tv_cardid,tv_ps,tv_equipmentStatusManagement,tv_equipmentLevel,tv_equipmentClass,tv_model;
        public ViewHolder(View itemView) {
            super(itemView);
            tview = itemView;
            tv_manufacturer = (TextView) itemView.findViewById(R.id.moudle_item_equ_single_choice_tv_equipmentmanufacturer);
            tv_name = (TextView) itemView.findViewById(R.id.moudle_item_equ_single_choice_tv_name);
            tv_cardid = (TextView) itemView.findViewById(R.id.moudle_item_equ_single_choice_tv_cardid);
            tv_ps = itemView.findViewById(R.id.moudle_item_equ_single_choice_tv_ps);
            tv_equipmentStatusManagement = itemView.findViewById(R.id.moudle_item_equ_single_choice_tv_equipmentStatusManagement);
            tv_equipmentLevel = itemView.findViewById(R.id.moudle_item_equ_single_choice_tv_equipmentLevel);
            tv_equipmentClass = itemView.findViewById(R.id.moudle_item_equ_single_choice_tv_equipmentclass);
            tv_model = itemView.findViewById(R.id.moudle_item_equ_single_choice_tv_equipmentmodel);
            tview.setOnClickListener(this);
        }

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