package com.sheep.gamegroup.view.adapter.expandadapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sheep.gamegroup.model.entity.RechargeEntity;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.SheepApp;

import java.util.List;

/**
 *任务游戏支付列表
 * Created by ljy on 2018/6/13.
 */

public class AdpPayGameDialog extends BaseAdapter {
    private List<RechargeEntity> list;

    public AdpPayGameDialog(List<RechargeEntity> list) {
        this.list = list;
    }

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

    @Override
    public RechargeEntity getItem(int position) {
        return list.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(SheepApp.getInstance()).inflate(R.layout.adp_pay_game_dialog, null);

            holder.pay_game_dialog_item_tv = convertView.findViewById(R.id.pay_game_dialog_item_tv);
            holder.pay_game_dialog_item_img = convertView.findViewById(R.id.pay_game_dialog_item_img);

            convertView.setTag(holder);
        }
        RechargeEntity priceShow = getItem(position);
        switch (priceShow.getId()){
            case 1://支付宝
            case 2://微信
                setValue(priceShow.isSelect() ? R.mipmap.gou_choose_blue : R.mipmap.gou_choose_gray,
                        priceShow.isSelect(),
                        holder.pay_game_dialog_item_img,
                        holder.pay_game_dialog_item_tv);
                break;
            case 3://绵羊
            default:
                setValue(priceShow.isSelect() ? R.mipmap.circle_check_blue : R.mipmap.circle_uncheck_blue,
                        priceShow.isSelect(),
                        holder.pay_game_dialog_item_img,
                        holder.pay_game_dialog_item_tv);
                break;
        }
        holder.pay_game_dialog_item_tv.setText(priceShow.getName()+"");

        return convertView;
    }

    class ViewHolder{
        ImageView pay_game_dialog_item_img;
        TextView pay_game_dialog_item_tv;
    }

    private void setValue(int intRes, boolean flag, ImageView view, TextView textView){
        Glide.with(SheepApp.getInstance())
                .load(intRes)
                .into(view);
        textView.setTextColor(flag ? SheepApp.getInstance().getResources().getColor(R.color.community_blue_text) : SheepApp.getInstance().getResources().getColor(R.color.black_444444));
    }
}
