package com.sipai.jspatrol.MonitorScreen;

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.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sipai.jspatrol.Bean.Nodes;
import com.sipai.jspatrol.R;
import com.sipai.jspatrol.URL.GuideMenuUrl;
import com.sipai.jspatrol.Webv.MonitorScreenActivity;

import java.util.List;

/**
 * created by lvliming on 2021/1/19
 */
public class MonitorScreenAdapter extends RecyclerView.Adapter<MonitorScreenAdapter.ViewHolder> {
    private Context context;
    private List<Nodes> list;

    public MonitorScreenAdapter(Context context, List<Nodes> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_monitor_screen_ps,parent,false);
        final ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.node.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = viewHolder.getAdapterPosition();
                Nodes item = list.get(position);
                MonitorScreenActivity.actionStart(context, GuideMenuUrl.url_monitor_screen+"?frameId="+item.getId(),item.getText());
            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Nodes item = list.get(position);
        holder.tv_title.setText(item.getText());
        if (item.getText().contains("间")) {
            holder.iv.setImageDrawable(context.getResources().getDrawable(R.mipmap.moudle_iv_room));
        }else if (item.getText().contains("池")) {
            holder.iv.setImageDrawable(context.getResources().getDrawable(R.mipmap.moudle_iv_pool));
        }else if (item.getText().contains("滤池")) {
            holder.iv.setImageDrawable(context.getResources().getDrawable(R.mipmap.moudle_iv_filter_pool));
        }else if (item.getText().contains("脱水机房")) {
            holder.iv.setImageDrawable(context.getResources().getDrawable(R.mipmap.moudle_iv_water_room));
        }else if (item.getText().contains("鼓风机房")) {
            holder.iv.setImageDrawable(context.getResources().getDrawable(R.mipmap.moudle_iv_wind_room));
        }else if (item.getText().contains("沉淀池")) {
            holder.iv.setImageDrawable(context.getResources().getDrawable(R.mipmap.moudle_iv_settling_));
        }else if (item.getText().contains("泵房")) {
            holder.iv.setImageDrawable(context.getResources().getDrawable(R.mipmap.moudle_iv_pump_room));
        }else if (item.getText().contains("进水")) {
            holder.iv.setImageDrawable(context.getResources().getDrawable(R.mipmap.moudle_iv_area));
        }else {
            holder.iv.setImageDrawable(context.getResources().getDrawable(R.mipmap.moudle_iv_pump_room));
        }
    }

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

    class ViewHolder extends RecyclerView.ViewHolder{
        View node;
        ImageView iv;
        TextView tv_title;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            node = itemView;
            iv = itemView.findViewById(R.id.item_monitor_screen_iv);
            tv_title = itemView.findViewById(R.id.item_monitor_screen_tv);
        }
    }

}
