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.GridViewEntity;
import com.sheep.gamegroup.model.entity.WithdrawalList;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.G;

import java.util.List;

/**
 * 提现下gridview的 adapter
 * Created by ljy on 2018/3/18.
 */

public class WithdrawalAdapter extends BaseAdapter {
    private Context context;
    private List<WithdrawalList> listData;

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

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

    @Override
    public WithdrawalList 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.withdrawal_gridview_item, null);

            holder.priceTv = convertView.findViewById(R.id.item_tv);

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

        holder.priceTv.setText(priceShow.getValue() +"元");

        return convertView;
    }

    class ViewHolder{
        TextView priceTv;
    }
}
