package com.module.backstage.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;

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.module.backstage.R;
import com.zyao89.view.zloading.ZLoadingView;
import com.zyao89.view.zloading.Z_TYPE;


public class CheckDialogAdapter extends RecyclerView.Adapter<CheckDialogAdapter.MyViewHolder> {

    private Context mContext;
    private String[] data;
    private onItemClickListener onItemClickListener;

    public void setOnItemClickListener(CheckDialogAdapter.onItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public CheckDialogAdapter(Context mContext, String[] data) {
        this.mContext = mContext;
        this.data = data;
    }

    public void setData(String[] data) {
        this.data = data;
    }

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

    @SuppressLint("RecyclerView")
    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.tvItemWifiName.setText(data[position]);
        if (position == data.length - 1) {
            onItemClickListener.onItemClick(holder.itemView, position);
        }
    }


    @Override
    public int getItemCount() {
        return data.length;
    }


    public static class MyViewHolder extends RecyclerView.ViewHolder {

        public TextView tvItemWifiName;
        public final ZLoadingView zLoadingView;
        public final ImageView ivSimSuccess;
        public final TextView tvItemWifiNameContext;

        public MyViewHolder(View itemView) {
            super(itemView);
            tvItemWifiName = (TextView) itemView.findViewById(R.id.tv_item_wifi_name);
            tvItemWifiNameContext = (TextView) itemView.findViewById(R.id.tv_item_wifi_name_context);

            ivSimSuccess = itemView.findViewById(R.id.iv_sim_success);
            zLoadingView = (ZLoadingView) itemView.findViewById(R.id.z_loading_view);
            zLoadingView.setLoadingBuilder(Z_TYPE.DOUBLE_CIRCLE);
            // 设置间隔百分比
           /* if (zLoadingView.mZLoadingBuilder != null)
            {
                zLoadingView.etDurationTimePercent(1.0f);
            }  */
            zLoadingView.setColorFilter(Color.parseColor("#86D2C3"), PorterDuff.Mode.SRC_ATOP);
        }

    }

    public interface onItemClickListener {
        void onItemClick(View view, int postion);
    }

}
