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.RechargeQEntity;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.G;

import java.util.List;

/**
 * 充值Q币gridview的 adapter
 */

public class RechargeQAdapter extends BaseAdapter {
    private Context context;
    private List<RechargeQEntity> listData;
    private boolean isInPut = false;

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


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

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

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

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

            // 获取屏幕宽度
            int W = G.WIDTH <G.HEIGHT ? G.WIDTH : G.HEIGHT;
            int cricleRadius = W / 4 -20;
            int h = cricleRadius  / 3;
            convertView.setLayoutParams(new AbsListView.LayoutParams(cricleRadius, ViewGroup.LayoutParams.WRAP_CONTENT));
//            convertView.setPadding(0,0,0,2);
            convertView.setTag(holder);
        }
        RechargeQEntity priceShow = getItem(position);
        if(isInPut){
            convertView.setBackground(context.getResources().getDrawable(R.drawable.btn_main_stroke_no_check_small));
            holder.item_tv_qb.setTextColor(ContextCompat.getColor(context,R.color.main_tab));
            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_qb.setTextColor(ContextCompat.getColor(context,R.color.main_tab_activated));
                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_qb.setTextColor(ContextCompat.getColor(context,R.color.main_tab));
                holder.item_tv_y.setTextColor(ContextCompat.getColor(context,R.color.main_tab));
            }
        }

        holder.item_tv_qb.setText(priceShow.getText());
        holder.item_tv_y.setText(priceShow.getPrice() +"元");

        return convertView;
    }

    class ViewHolder{
        TextView item_tv_qb;
        TextView item_tv_y;
    }
}
