package com.duben.microtribe.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.duben.library.utils.GlideUtils;
import com.duben.microtribe.R;
import com.duben.microtribe.mvp.model.BannerBean;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * 自定义布局，图片+标题
 */

public class ImageTitleAdapter extends BannerAdapter<BannerBean, ImageTitleHolder> {

    private Context context;

    public ImageTitleAdapter(List<BannerBean> mDatas) {
        super(mDatas);
    }

    @Override
    public ImageTitleHolder onCreateHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        return new ImageTitleHolder(LayoutInflater.from(context).inflate(R.layout.banner_image_title, parent, false));
    }

    @Override
    public void onBindView(ImageTitleHolder holder, BannerBean data, int position, int size) {
//        holder.imageView.setImageResource(data.getImageRes());
        if (data.getImageRes() != null) {
            GlideUtils.INSTANCE.loadImageViewGifForCenterCrop(context, data.getImageRes(), holder.imageView);
        }
        holder.title.setText(data.getTitle());
    }

}
