package com.tofly.ghrq_route.common.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.lcp.arecyclerview.widget.ARecyclerBaseAdapter;
import com.tofly.ghrq_route.R;
import com.tofly.ghrq_route.module.planPointRepair.domain.PlanPointRepair;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Amu on 2017/5/22.
 */

public class RepairHistoryAdapter extends ARecyclerBaseAdapter<RepairHistoryAdapter.MyViewHolder, PlanPointRepair> {

    public RepairHistoryAdapter(Context context, List<PlanPointRepair> data) {
        super(context, data);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(mContext).inflate(R.layout.listview_repair_history_item, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(rootView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        PlanPointRepair pointRepair = getItem(position);
        if (pointRepair != null) {
            holder.textRepairSid.setText(pointRepair.getPoint_id());
            holder.textSubmitTime.setText(pointRepair.getCreate_time());
            holder.textRepairAddr.setText(pointRepair.getAddress());

            if (onItemClickListener != null) {
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemClickListener.onItemClick(holder.itemView, holder.getLayoutPosition());
                    }
                });
            }
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.image_build_icon)
        ImageView imageBuildIcon;
        @BindView(R.id.text_repair_sid)
        TextView textRepairSid;
        @BindView(R.id.text_submit_time)
        TextView textSubmitTime;
        @BindView(R.id.text_repair_subtype)
        TextView textRepairSubtype;
        @BindView(R.id.text_repair_addr)
        TextView textRepairAddr;


        MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
