package com.sheep.gamegroup.view.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

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

import java.util.List;

/**
 * 游戏代充 gridview
 * Created by ljy on 2018/7/9.
 */

public class AdpGameAgencyRecharge extends BaseAdapter {
    private Context context;
    private List<Object> list;

    public AdpGameAgencyRecharge(Context context, List<Object> list) {
        this.context = context;
        this.list = list;
    }

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

    @Override
    public GridViewEntity getItem(int position) {
        return (GridViewEntity) list.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.adp_level_gridview_item, null);
            holder.name_tv = convertView.findViewById(R.id.name_tv);
            holder.line_view = convertView.findViewById(R.id.line_view);

            convertView.setTag(holder);
        }

        int with = 70;
        if(getItem(position).getName().length() > 4){
            with = 140;
        }else {
            with = 60;
        }
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(with, 8);
        params.gravity = Gravity.CENTER_HORIZONTAL;
        params.setMargins(0, 20,0,0);
        holder.line_view.setLayoutParams(params);
        if (getItem(position).isSelectState()){
            holder.name_tv.setTextColor(context.getResources().getColor(R.color.blue_end));
            holder.line_view.setVisibility(View.VISIBLE);
        }else{
            holder.name_tv.setTextColor(context.getResources().getColor(R.color.txt_black_818181));
            holder.line_view.setVisibility(View.INVISIBLE);
        }
        holder.name_tv.setText(getItem(position).getName()+"");
        return convertView;
    }

    class ViewHolder{
        TextView name_tv;
        View line_view;
    }
}
