package com.uiui.zyappstore.adapter;

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

import androidx.recyclerview.widget.RecyclerView;

import com.uiui.zyappstore.R;
import com.uiui.zyappstore.bean.GlideCircleWithBorder;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by fht on 2019/11/08.
 */

public class ShowImageAdapter extends RecyclerView.Adapter<ShowImageAdapter.ImageViewHolder> {

    private List<String> mSrcList;
    private Context mContext;


    public ShowImageAdapter(List<String> mSrcList, Context context) {
        this.mContext = context;
        this.mSrcList = mSrcList;
    }

    @Override
    public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ImageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_image, parent, false));
    }

    @Override
    public void onBindViewHolder(ImageViewHolder holder, int position) {
        String src = mSrcList.get(position);
        Glide.with(mContext)
                .asBitmap()
                .load(src)
                .placeholder(R.drawable.ic_place_holder)
                .transform(new GlideCircleWithBorder(mContext))
                .into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return mSrcList.size();
    }

    public static class ImageViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        public ImageViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.item_iv);
        }
    }

}
