package com.zhaohaoting.framework.abs.adapter;


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


import com.zhaohaoting.framework.view.indicator.IndicatorViewPager;

import java.util.List;

/**
 * author：Created by zhaohaoting on 2018/1/10 11:51
 * email：526309416@qq.com
 * desc：
 */
public abstract class BannerAdapter<T> extends IndicatorViewPager.IndicatorViewPagerAdapter {
    private List<T> bannerAdList;
    private int tabIndicator;

    public BannerAdapter(List<T> bannerAdList, int tabIndicator) {
        this.bannerAdList = bannerAdList;
        this.tabIndicator = tabIndicator;
    }

    @Override
    public View getViewForTab(int position, View convertView, ViewGroup container) {
        if (convertView == null) {
            convertView = LayoutInflater.from(container.getContext()).inflate(tabIndicator, container, false);

        }
        return convertView;
    }

    @Override
    public View getViewForPage(final int position, View convertView, ViewGroup container) {
        ImageView imageView;
        if (convertView == null) {
            imageView = new ImageView(container.getContext());
            imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            convertView = imageView;
        } else {
            imageView = (ImageView) convertView;
        }
        T bannerAd = bannerAdList.get(position);
        setViewData(imageView, bannerAd);
//        GlideUtils.loadBlackImage(container.getContext(), bannerAd.getImgUrl(), imageView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              itemOnClick(v, position);
            }
        });
        return convertView;
    }

    public abstract void itemOnClick(View view, int position);


    public abstract void setViewData(ImageView imageView, T bannerAd);

//        @Override
//        public int getItemPosition(Object object) {
//            return RecyclingPagerAdapter.POSITION_NONE;
//        }

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