package com.sheep.gamegroup.view.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sheep.gamegroup.model.entity.RechargeEntity;
import com.sheep.jiuyan.samllsheep.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 充值gridview的 adapter
 */

public class RechargeAdapter extends BaseAdapter {
    private Context context;
    private List<RechargeEntity> listData =  new ArrayList<>();
    int select = -1;

    public RechargeAdapter(Context context) {
        this.context = context;
    }

    public void setSelect(int select) {
        this.select = select;
    }

    public void addAll(List<RechargeEntity> list){
        this.listData.clear();
        this.listData.addAll(list);
        notifyDataSetChanged();
    }

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

    @Override
    public RechargeEntity getItem(int position) {
        return listData.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Object tag = convertView == null ? null : convertView.getTag();
        ViewHolder holder;
        if(tag instanceof ViewHolder){
            holder = (ViewHolder) tag;
        }else {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.recharge_gridview_item, null);
            holder.tv_pay = convertView.findViewById(R.id.tv_pay);
            convertView.setTag(holder);
        }
        RechargeEntity priceShow = getItem(position);
        if (position == select){
            holder.tv_pay.setBackground(context.getResources().getDrawable(R.drawable.layer_list_check_rectgangle_small));
            holder.tv_pay.setTextColor(ContextCompat.getColor(context,R.color.main_tab_activated));
        }else{
            holder.tv_pay.setBackground(context.getResources().getDrawable(R.drawable.btn_main_stroke_no_check_small));
            holder.tv_pay.setTextColor(ContextCompat.getColor(context,R.color.main_tab));

        }

        holder.tv_pay.setText(priceShow.getName());

        return convertView;
    }

    class ViewHolder{
        TextView tv_pay;
    }
}
