package etelligens.com.foodsafety.adapter; import android.content.Context; import android.graphics.Bitmap; import android.net.Uri; import android.provider.MediaStore; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import java.io.IOException; import java.util.ArrayList; import etelligens.com.foodsafety.R; import etelligens.com.foodsafety.model.AddImageCustomBakendModal; import static etelligens.com.foodsafety.utils.EndPoint.ETE_IMAGE_BASEURL; public class AddImageCustomLabelBakendAdapter extends RecyclerView.Adapter { Context context; ArrayList modalArrayList; PassImage passImage; public interface PassImage { void sendImage(AddImageCustomBakendModal addImageCustomBakendModal, int id); } public AddImageCustomLabelBakendAdapter(Context context, ArrayList list, PassImage passImage) { this.context = context; this.modalArrayList = list; this.passImage = passImage; } View view; @NonNull @Override public AddImageCustomLabelBakendAdapter.AddImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) { view = LayoutInflater.from(context).inflate(R.layout.item_layout_add_image_custom_label_backend, parent, false); return new AddImageViewHolder(view); } @Override public void onBindViewHolder(@NonNull AddImageCustomLabelBakendAdapter.AddImageViewHolder holder, int i) { final AddImageCustomBakendModal addImageCustomBakendModal = modalArrayList.get(i); final int id = addImageCustomBakendModal.getId(); String image = addImageCustomBakendModal.getImage(); String bMapImage=addImageCustomBakendModal.getLabel_image(); if (image != null) { Glide.with(context).load(ETE_IMAGE_BASEURL+image).into(holder.addimage); } else { if (bMapImage != null ) { Bitmap bMap = null; try { bMap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), Uri.parse(bMapImage)); } catch (IOException e) { e.printStackTrace(); } if (bMap != null) { holder.addimage.setImageBitmap(bMap); } System.out.println(bMap + "......bmap..bhar......sssss"); } System.out.println(image + "..............sssss"); } holder.addimage.setOnClickListener(v -> passImage.sendImage(addImageCustomBakendModal, id)); } @Override public int getItemCount() { return modalArrayList.size(); } public class AddImageViewHolder extends RecyclerView.ViewHolder { ImageView addimage; public AddImageViewHolder(View itemview) { super(itemview); addimage = itemview.findViewById(R.id.custom_add_image); } } }