Ronel101

FoodListAdapter

Apr 19th, 2021
588
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.finalapp;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.graphics.Bitmap;
  7. import android.graphics.BitmapFactory;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.AdapterView;
  12. import android.widget.BaseAdapter;
  13. import android.widget.Button;
  14. import android.widget.TextView;
  15.  
  16. import com.bumptech.glide.Glide;
  17. import com.google.android.gms.tasks.OnSuccessListener;
  18. import com.google.firebase.database.DatabaseReference;
  19. import com.google.firebase.database.FirebaseDatabase;
  20. import com.google.firebase.storage.FileDownloadTask;
  21. import com.google.firebase.storage.FirebaseStorage;
  22. import com.google.firebase.storage.StorageReference;
  23.  
  24. import java.io.File;
  25. import java.io.IOException;
  26. import java.util.ArrayList;
  27.  
  28. import de.hdodenhof.circleimageview.CircleImageView;
  29.  
  30. public class FoodListAdapter extends BaseAdapter {
  31.  
  32.     private ArrayList<Food> foodArrayList;
  33.     private String pic_path;
  34.     private Context context;
  35.  
  36.     private DatabaseReference ref=null;
  37.  
  38.     public FoodListAdapter(ArrayList<Food> foodArrayList, Context context, String pic_path)
  39.     {
  40.         this.foodArrayList = foodArrayList;
  41.         this.context = context;
  42.         this.pic_path=pic_path;
  43.     }
  44.  
  45.     @Override
  46.     public int getCount()
  47.     {
  48.         return this.foodArrayList.size();
  49.     }
  50.  
  51.     @Override
  52.     public Object getItem(int position)
  53.     {
  54.         return null;
  55.     }
  56.  
  57.     @Override
  58.     public long getItemId(int position)
  59.     {
  60.         return 0;
  61.     }
  62.  
  63.     @Override
  64.     public View getView(final int position, final View convertView, ViewGroup parent)
  65.     {
  66.         ref= FirebaseDatabase.getInstance().getReference("Food");
  67.  
  68.         LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  69.  
  70.         View show_food_search = layoutInflater.inflate(R.layout.foodrow, parent, false);
  71.         TextView name= (TextView)show_food_search.findViewById(R.id.foodlist_name);
  72.         TextView username= (TextView)show_food_search.findViewById(R.id.foodlist_des);
  73.  
  74.         name.setText(foodArrayList.get(position).getFoodName());
  75.         username.setText(foodArrayList.get(position).getDescription());
  76.  
  77.         final CircleImageView imageView =show_food_search.findViewById(R.id.img_FoodList);
  78.  
  79.         String picname=this.foodArrayList.get(position).getFoodpic();
  80.  
  81.         String suffix=picname.substring(picname.lastIndexOf(".")+1);
  82.  
  83.         FirebaseStorage storage = FirebaseStorage.getInstance();
  84.  
  85.         //StorageReference storageRef = storage.getReferenceFromUrl(pic_path).child("Food").child(picname);
  86.         StorageReference storageRef = storage.getReference().child("Food").child(picname);
  87.  
  88.         Glide.with(context)
  89.                 .load(storageRef)
  90.                 .into(imageView);
  91. /*
  92.         try
  93.         {
  94.             final File localfile=File.createTempFile(picname,suffix);
  95.  
  96.             storageRef.getFile(localfile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>()
  97.             {
  98.                 @Override
  99.                 public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot)
  100.                 {
  101.                     Bitmap bitmap = BitmapFactory.decodeFile(localfile.getAbsolutePath());
  102.                     // set image based on selected text
  103.                     imageView.setImageBitmap(bitmap);
  104.                 }
  105.             });
  106.         }
  107.         catch (IOException e)
  108.         {
  109.             e.printStackTrace();
  110.         }
  111.  
  112.  */
  113.  
  114.  
  115.         // final String id=this.foodArrayList.get(position);
  116.  
  117.  
  118.  
  119.         return show_food_search;
  120.     }
  121.  
  122. }
  123.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×