package com.sybotan.android.demo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sybotan.android.demo.R;
import com.sybotan.android.demo.bean.result.PipeListModel;

import java.util.List;

/**
 * Created by lihao.
 * Date: 6/15/21
 */
public class PipeAdapter extends BaseRecyclerViewAdapter<PipeListModel> {
    public PipeAdapter(Context context, List<PipeListModel> beans) {
        super(context, beans);
    }

    @Override
    protected int getItemLayoutId(int viewType) {
        return R.layout.item_pipe_type;
    }

    @Override
    protected void onBindDataToView(ViewHolder holder, PipeListModel model) {
        TextView pipe = holder.getView(R.id.pipe);
        holder.setText(R.id.pipe, model.sysName + "-" + model.name);
        holder.getView(R.id.pipe).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < mBeans.size(); i++) {
                    mBeans.get(i).isCheck = false;
                }
                model.isCheck = true;
                notifyDataSetChanged();
            }
        });
        if (model.isCheck) {
            pipe.setBackgroundResource(R.drawable.shape_filter_selected);
            pipe.setTextColor(mContext.getResources().getColor(R.color.white));
        } else {
            pipe.setBackgroundResource(R.drawable.shape_filter_normal);
            pipe.setTextColor(mContext.getResources().getColor(R.color.grey_900));
        }
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }
}
