Blame view

footsafety/app/src/main/java/etelligens/com/foodsafety/adapter/AddImageCustomLabelBakendAdapter.java 3.11 KB
f7a13682   “wangming”   项目初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  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<AddImageCustomLabelBakendAdapter.AddImageViewHolder> {
  
      Context context;
      ArrayList<AddImageCustomBakendModal> modalArrayList;
  
      PassImage passImage;
  
      public interface PassImage {
          void sendImage(AddImageCustomBakendModal addImageCustomBakendModal, int id);
      }
  
      public AddImageCustomLabelBakendAdapter(Context context, ArrayList<AddImageCustomBakendModal> 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);
          }
  
      }
  }