package com.ycgis.macall.personalcenter.v.adapter;

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

import androidx.core.content.ContextCompat;

import com.rs.macall.androidx.basemodel.base.BaseBackAdapter;
import com.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.m.adapterbean.SelectAddressBean;

import java.util.List;

/**
 * created by:   Macall
 * create time:  2022/11/14 18:20
 * copyright:    @ruansee.com
 * Describe:
 */
public class SelectAddressAdapter extends BaseBackAdapter<SelectAddressBean> {

    public SelectAddressAdapter(Context context, List<SelectAddressBean> datalist) {
        super(context, datalist);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_grid_select_ds,parent,false);
            holder = new Holder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (Holder) convertView.getTag();
        }
        if (getItem(position).isSelect()){
            holder.tv_name.setBackground(ContextCompat.getDrawable(context,R.drawable.bk_main_color_round_8));
            holder.tv_name.setTextColor(ContextCompat.getColor(context,R.color.mainColor));
        }else {
            holder.tv_name.setBackground(ContextCompat.getDrawable(context,R.drawable.card_white_round_8));
            holder.tv_name.setTextColor(ContextCompat.getColor(context,R.color.colorGrey7));
        }
        holder.tv_name.setText(getItem(position).getName());
        return convertView;
    }

    private class Holder{
        private View itemView;
        private TextView tv_name;

        public Holder(View itemView) {
            this.itemView = itemView;
            tv_name = itemView.findViewById(R.id.tv_name);
        }
    }


}
