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 DebugParameterYAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private final int TITLE = 0;
    private final int NORMAL = 1;

    private int[] datas = {
            R.string.ioy0,R.string.ioy1,R.string.ioy2,R.string.ioy3, R.string.ioy4,
            R.string.ioy5,R.string.ioy6, R.string.ioy7,R.string.ioy10, R.string.ioy11,
            R.string.ioy12,R.string.ioy13,R.string.ioy14,R.string.ioy15,R.string.ioy16,
            R.string.ioy17, R.string.ioy20,R.string.ioy21,R.string.ioy22,R.string.ioy23,
            R.string.ioy24,R.string.ioy25,

    };
    private String[] address = {
            "00", "01", "02", "03","04",
            "05","06", "07", "10", "11",
            "12","13", "14", "15", "16",
            "17","20", "21", "22", "23",
            "24","25"
    };

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

    private DebugParameterYAdapter.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 DebugParameterYAdapter.TitleViewHolder(inflate);
        }
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_xy, parent, false);
        return new DebugParameterYAdapter.ViewHolder(inflate);
    }

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

        } else if (holder instanceof DebugParameterYAdapter.ViewHolder) {
            DebugParameterYAdapter.ViewHolder mViewHolder = (DebugParameterYAdapter.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);
        }
    }

}
