package com.ycgis.macall.personalcenter.v.photoview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.rs.macall.androidx.basemodel.base.BaseRecyclerAdapter;
import com.ycgis.macall.personalcenter.R;

import java.util.List;

/**
 * @Author macall
 * @Create 2019/12/12 0012
 * @Describe
 */
public class PhotoViewAdapter extends BaseRecyclerAdapter<String,PhotoViewAdapter.ViewHolder> {

    public PhotoViewAdapter(Context context, List<String> dataList) {
        super(context, dataList);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.photo_view_layout,viewGroup,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        Bitmap bitmap = BitmapFactory.decodeFile(getDataItem(i));
        if (bitmap!= null){
            viewHolder.iv_photo.setImageBitmap(bitmap);
        }
    }

    public class ViewHolder extends BaseRecyclerAdapter.ViewHolder{
        private PhotoView iv_photo;

        public ViewHolder(View itemView) {
            super(itemView);
            iv_photo = (PhotoView) itemView;
            iv_photo.setZoomTransitionDuration(500);
            if (listClickListener != null){
                itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        listClickListener.onItemClickListener(v,getAdapterPosition());
                    }
                });
            }
        }
    }
}
