package com.mints.goodmoney.ui.adapter;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.mints.goodmoney.R;
import com.mints.goodmoney.common.Constant;
import com.mints.goodmoney.manager.BxmManager;
import com.mints.goodmoney.mvp.model.BannerBean;
import com.mints.goodmoney.utils.ForegroundOrBackground;
import com.mints.library.utils.GlideUtils;

import java.util.List;

/**
 * 描述：我的界面
 * 作者：孟崔广
 * 时间：2019/10/28 19:21
 * 邮箱：mengcga@163.com
 */
public class GvMyAdapter extends BaseAdapter {

    private List<BannerBean.ListBean> orders;
    private Context context;
    private Activity activity;

    public GvMyAdapter(Context context, Activity activity, List<BannerBean.ListBean> orders) {
        this.orders = orders;
        this.context = context;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        return orders == null ? 0 : orders.size();
    }

    @Override
    public Object getItem(int position) {
        return orders.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("WrongViewCast")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;

        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.item_list_my, null);
            viewHolder = new ViewHolder();

            viewHolder.fl_my_icon = (FrameLayout) convertView.findViewById(R.id.fl_my_icon);
            viewHolder.ic_my_icon = (ImageView) convertView.findViewById(R.id.ic_my_icon);
            viewHolder.tv_my_title = (TextView) convertView.findViewById(R.id.tv_my_title);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        BannerBean.ListBean data = orders.get(position);
        if (data != null) {
            GlideUtils.loadImageViewGifUrl(context, viewHolder.ic_my_icon, data.getImgUrl());
            viewHolder.tv_my_title.setText(data.getTitle());

            if (TextUtils.equals(data.getToUrl(), Constant.HOT_ACTIVITY_BXM)) {
                BxmManager.INSTANCE.loadButtonAd(activity, viewHolder.fl_my_icon);
            }
        }
        return convertView;
    }

    class ViewHolder {
        public ImageView ic_my_icon;
        public FrameLayout fl_my_icon;
        public TextView tv_my_title;
    }
}

