package com.tenlionsoft.baselib.core.widget.base;

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

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.core.beans.BaseImageBean;
import com.tenlionsoft.baselib.utils.ConvertUtils;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * 作者: adam
 * 日期: 2020/6/10 - 5:51 PM
 * 邮箱: itgaojian@163.com
 * 描述:
 */
public class BannerImageTextAdapter extends BannerAdapter<BaseImageBean, BannerTextHolder> {

    public BannerImageTextAdapter(List<BaseImageBean> datas) {
        super(datas);

    }

    @Override
    public BannerTextHolder onCreateHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_banner_text, parent, false);
        return new BannerTextHolder(itemView);
    }

    @Override
    public void onBindView(BannerTextHolder holder, BaseImageBean data, int position, int size) {
        RoundedCornersTransform roundedCornersTransform = new RoundedCornersTransform(holder.itemView.getContext(), ConvertUtils.dp2px(2));
        roundedCornersTransform.setNeedCorner(false, false, false, false);
        RequestOptions options = new RequestOptions()
                .error(R.drawable.ic_img_default_banner)
                .placeholder(R.drawable.ic_img_default_banner)
                .transform(roundedCornersTransform)
                .skipMemoryCache(false)
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                .fitCenter();
        Glide.with(holder.itemView.getContext())
                .asBitmap()
                .load(data.getImgUrl())
                .apply(options)
                .into(holder.mIvCover);
        holder.mTvName.setText(data.getName());
    }
}
