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.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sheep.gamegroup.model.entity.RechargePriceEntity;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.G;

import java.util.List;

/**
 * 充值gridview的 adapter
 */

public class RechargePriceAdapter extends BaseAdapter {
    private Context context;
    private List<RechargePriceEntity> listData;
    private  boolean inPut = false;

    public RechargePriceAdapter(Context context, List<RechargePriceEntity> listData) {
        this.context = context;
        this.listData = listData;
    }

    public void setInPut(boolean inPut) {
        this.inPut = inPut;
        notifyDataSetChanged();
    }

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

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

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

    @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.rechargeprice_gridview_item, null);

            holder.item_tv_y = convertView.findViewById(R.id.item_tv_y);

            convertView.setTag(holder);
        }
        RechargePriceEntity priceShow = getItem(position);
        if(inPut){
            convertView.setBackground(context.getResources().getDrawable(R.drawable.btn_main_stroke_no_check_small));
            holder.item_tv_y.setTextColor(ContextCompat.getColor(context,R.color.main_tab));
        }else{
            if (priceShow.isSelectState()){
                convertView.setBackground(context.getResources().getDrawable(R.drawable.layer_list_check_rectgangle_small));
                holder.item_tv_y.setTextColor(ContextCompat.getColor(context,R.color.main_tab_activated));
            }else{
                convertView.setBackground(context.getResources().getDrawable(R.drawable.btn_main_stroke_no_check_small));
                holder.item_tv_y.setTextColor(ContextCompat.getColor(context,R.color.main_tab));
            }
        }

        holder.item_tv_y.setText(priceShow.getValue());

        return convertView;
    }

    class ViewHolder{
        TextView item_tv_y;
    }
}
