package com.trace.drawing.people.item;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import com.trace.drawing.people.databinding.RecyclerViewAllBinding;
import com.trace.drawing.people.page.PreviewPage;
import com.trace.drawing.people.tools.App;
import com.trace.drawing.people.tools.Common;

import java.util.List;

public class ViewAllItem extends RecyclerView.Adapter<ViewAllItem.HomeVH> {


    private Context mCon;
    private List<String> data;



    public ViewAllItem(Context mCon, List<String> bitmapList) {
        this.mCon = mCon;
        data = bitmapList;
    }



    @NonNull
    @Override
    public HomeVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        return new HomeVH( RecyclerViewAllBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull HomeVH holder, int position) {

        String name = data.get(position);
        Log.d(App.TAG,"--------name="+name);
          Common.loadImageFromAssets(mCon, name, holder.binding.imPreview, bitmap -> {

          });


        holder.binding.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mCon, PreviewPage.class);
                intent.putExtra(App.Key_Camera, name);
                mCon.startActivity(intent);
            }
        });


    }

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

    public static class HomeVH extends RecyclerView.ViewHolder {
        private RecyclerViewAllBinding binding;




        public HomeVH(@NonNull RecyclerViewAllBinding itemView) {
            super(itemView.getRoot());
            binding = itemView;
        }


    }
}
