package com.sheep.gamegroup.view.adapter;

import android.content.Context;
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) {
        ViewHolder holder = null;
        if (holder == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.withdrawal_gridview_item, null);

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

            // 获取屏幕宽度
            int W = G.WIDTH <G.HEIGHT ? G.WIDTH : G.HEIGHT;
            int cricleRadius = W / 4  -50;
            int h = cricleRadius  / 3;
            convertView.setLayoutParams(new AbsListView.LayoutParams(cricleRadius, ViewGroup.LayoutParams.WRAP_CONTENT));
//            convertView.setPadding(0,0,0,2);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        GridViewEntity priceShow = getItem(position).getGridViewEntity();
        if (priceShow.isSelectState()){
            convertView.setBackground(context.getResources().getDrawable(R.drawable.sp_bg_gradient_rectangle_blue));
        }else{

            convertView.setBackground(context.getResources().getDrawable(R.drawable.sp_rectangle_bg_gray_radius));
        }

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

        return convertView;
    }

    class ViewHolder{
        TextView priceTv;
    }
}
