package com.hongyegroup.cpt_parttime.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.guadou.lib_baselib.utils.CommUtils;
import com.hongyegroup.cpt_parttime.R;
import com.hongyegroup.cpt_parttime.bean.PopupTitleSubTitleBean;

import java.util.List;

public class PositionGridAdapter extends BaseAdapter {

    private List<PopupTitleSubTitleBean.SubBean> mDatas;

    public PositionGridAdapter(List<PopupTitleSubTitleBean.SubBean> datas) {
        this.mDatas = datas;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = CommUtils.inflate(R.layout.item_position_grid);
            viewHolder = new ViewHolder();
            viewHolder.tv = (TextView) convertView.findViewById(R.id.tv_position_name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        PopupTitleSubTitleBean.SubBean bean = mDatas.get(position);
        viewHolder.tv.setText(bean.name);

        //动态的设置背景
        if (bean.isSelected) {
            viewHolder.tv.setTextColor(CommUtils.getColor(R.color.app_blue));
            viewHolder.tv.setBackgroundResource(R.drawable.shape_popup_position_active);
        } else {
            viewHolder.tv.setTextColor(CommUtils.getColor(R.color.black_33));
            viewHolder.tv.setBackgroundResource(R.drawable.shape_popup_position_unactive);
        }

        return convertView;
    }

    static class ViewHolder {
        public TextView tv;
    }

}
