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.sign.domain.SignHistoryDataBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

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

public class SignDataAdapter extends ARecyclerBaseAdapter<SignDataAdapter.MyViewHolder, SignHistoryDataBean> {

    private Context mContext;

    private List<SignHistoryDataBean> mData;

    String[] signStatus;

    public SignDataAdapter(Context context, List<SignHistoryDataBean> data) {
        super(context, data);
        mContext = context;
        mData = data;
        signStatus = mContext.getResources().getStringArray(R.array.sign_status);
    }

    public void setData(List<SignHistoryDataBean> data) {
        mData = data;
        notifyDataSetChanged();
    }

    @Override
    public SignHistoryDataBean getItem(int position) {
        SignHistoryDataBean signDataBean = null;
        if (position < mData.size()) {
            signDataBean = mData.get(position);
        }
        return signDataBean;
    }

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

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

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        SignHistoryDataBean signDataBean = getItem(position);
        if (signDataBean != null) {
            int status = signDataBean.getSignType();
            if (status >= 0 && status < signStatus.length){
                holder.textSignOn.setText(signStatus[status]);
            }
            holder.textSignOnTime.setText(signDataBean.getSignTime());
            holder.textSignOnAddr.setText(signDataBean.getSignAddr());
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.imageview_plan_icon)
        ImageView imageviewPlanIcon;
        @BindView(R.id.text_sign_on)
        TextView textSignOn;
        @BindView(R.id.text_sign_on_time)
        TextView textSignOnTime;
        @BindView(R.id.text_sign_on_addr)
        TextView textSignOnAddr;
        @BindView(R.id.text_sign_on_detail)
        TextView textSignOnDetail;

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