package com.adealink.weparty.commonui.widget.banner.adapter;

import android.net.Uri;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.adealink.frame.image.view.NetworkImageView;
import com.adealink.weparty.commonui.widget.banner.holder.BannerImageHolder;

import java.util.List;

/**
 * 最简单的图片适配器，传入List<String>，并且实现图片加载
 */
public class SimpleNetworkImageBannerAdapter extends BannerAdapter<String, BannerImageHolder> {

    public SimpleNetworkImageBannerAdapter(List<String> mData) {
        super(mData);
    }

    @Override
    public BannerImageHolder onCreateHolder(ViewGroup parent, int viewType) {
        NetworkImageView imageView = new NetworkImageView(parent.getContext());
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        imageView.setLayoutParams(params);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new BannerImageHolder(imageView);
    }

    @Override
    public void onBindView(BannerImageHolder holder, String data, int position, int size) {
        ((NetworkImageView) holder.imageView).setImageURI(Uri.parse(data));
    }
}
