package com.example.beijing_daxing.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


// import com.bumptech.glide.Glide;
import com.bumptech.glide.Glide;
import com.example.beijing_daxing.R;

import java.util.List;

/**
 * Created by wangh on 2021/1/28-14:02。
 */
public class PictureAdapter extends RecyclerView.Adapter<PictureAdapter.MyViewHolder> {
    private Context context;
    private List<Bitmap> list;
    private LayoutInflater inflater;
    private ViewOnClickCall call;
    public interface ViewOnClickCall{
        void onclickCall(int position);
    }
    public PictureAdapter(Context context, ViewOnClickCall call) {
        this.context = context;
        this.call=call;
        inflater=LayoutInflater.from(context);
    }

    public void setList(List<Bitmap> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v=inflater.inflate(R.layout.item_photo,parent,false);
        return new MyViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, @SuppressLint("RecyclerView") int position) {
        Bitmap info=list.get(position);

//        holder.img.setImageBitmap(info);
        Glide.with(context).load(info).into( holder.img);
        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                call.onclickCall(position);
            }
        });
    }

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

    class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView img;
        private TextView button;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            img=itemView.findViewById(R.id.item_photoImg);
            button=itemView.findViewById(R.id.item_photoButton);
        }
    }
}
