package com.sunzee.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sunzee.R;

public class DebugParameterXAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private final int TITLE = 0;
    private final int NORMAL = 1;

    private int[] datas = {
            R.string.iox2, R.string.iox3, R.string.iox4,
            R.string.iox5, R.string.iox7, R.string.iox10,
            R.string.iox11, R.string.iox12, R.string.iox13,
            R.string.iox14, R.string.iox15, R.string.iox16,
            R.string.iox17, R.string.iox20, R.string.iox21,
            R.string.iox22, R.string.iox23, R.string.iox24,
            R.string.iox25, R.string.iox26, R.string.iox27,
    };
    private String[] address = {
            "02", "03", "04", "05", "07",
            "10", "11", "12", "13", "14",
            "15", "16", "17", "20", "21",
            "22", "23", "24", "25", "26",
            "27",
    };

    public void setItemListener(ItemMaintainClickListener listener) {
        this.listener = listener;
    }

    private ItemMaintainClickListener listener;

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == TITLE) {
            View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_xy_title, parent, false);
            return new DebugParameterXAdapter.TitleViewHolder(inflate);
        }
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_xy, parent, false);
        return new DebugParameterXAdapter.ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof TitleViewHolder) {

        } else if (holder instanceof ViewHolder) {
            ViewHolder mViewHolder = (ViewHolder) holder;

            mViewHolder.tvAddress.setText(address[position - 1]);
            mViewHolder.tvName.setText(datas[position - 1]);


        }

    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TITLE;
        }
        return NORMAL;
    }

    @Override
    public int getItemCount() {
        return datas.length + 1;
    }

    public interface ItemMaintainClickListener {
        /**
         * @param view     控件
         * @param position 位置
         */
        void onItemListener(View view, int position);

    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvAddress;
        TextView tvName;
        public ImageView ivState;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvAddress = itemView.findViewById(R.id.tv_address);
            tvName = itemView.findViewById(R.id.tv_name);
            ivState = itemView.findViewById(R.id.iv_state);
        }
    }

    public static class TitleViewHolder extends RecyclerView.ViewHolder {
        public TitleViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }

}
