package com.bc_chat.account.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bc_chat.account.R;
import com.bc_chat.bc_base.entity.SplashImage;
import com.zhaohaoting.framework.utils.glid.GlideUtils;
import com.zhaohaoting.framework.view.indicator.IndicatorViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xxh on 2018-4-11.
 */

public class GuideAdapter extends IndicatorViewPager.IndicatorViewPagerAdapter {
    private List<SplashImage> urlList = new ArrayList<>();
    private final LayoutInflater inflate;
    private Context context;

    public GuideAdapter(Context context) {
        this.context = context;
        inflate = LayoutInflater.from(context);
    }

    public void notifyDataSetChanged(List<SplashImage> urls) {
        urlList.clear();
        urlList.addAll(urls);
        super.notifyDataSetChanged();
    }

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

    @Override
    public View getViewForTab(int position, View convertView, ViewGroup container) {
        if (convertView == null) {
            convertView = inflate.inflate(R.layout.tab_guide, container, false);
        }
        return convertView;
    }

    @Override
    public View getViewForPage(int position, View convertView, ViewGroup container) {
        ImageView imageView = new ImageView(container.getContext());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        GlideUtils.loadImage(context, urlList.get(position).getImg(), imageView);
        return imageView;
    }

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