skip to Main Content

So I am currently using FirestoreRecyclerAdapter to display images from the Firebase Storage via the Firestore database, that is

Firebase Storage file url > Firestore database url > RecyclerView (FirestoreRecyclerAdapter)

This is fine for a small number of images. But when dealing with 150 images per set, this is starting to become a hassle.

Is there a more efficient way of dealing with this? Like looping through all the images from the Firebase Storage and displaying them directly onto the RecyclerView?

Kindly point me to a tutorial if it exists, preferably Kotlin. I’m not really with docs. I know I’m already asking for too much. Thanks!

2

Answers


  1. One way to improve the efficiency of displaying images in a RecyclerView is to use a library that handles image loading and caching. Glide and Picasso are two popular options for this. Both libraries can load images directly from Firebase Storage using the StorageReference object and can cache the images to improve performance.

    Maybe some code like that would work:

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val imageRef = getItem(position).imageRef // get the StorageReference for the image
        Glide.with(context)
            .load(imageRef)
            .into(holder.imageView)
    }
    

    But it needs some setup, please check it here in this answer: https://stackoverflow.com/a/48762436/7334951

    Login or Signup to reply.
  2. As I understand from your question, you have added some images in Cloud Storage and the corresponding URLs in Firestore. In order to display the images from Cloud Storage in a RecyclerView, you read the URLs from Firestore first. This practice is quite common when you want to store details about the files you’re working with. However, if you only want to display the images from Storage, there is no need to read the URLs from Firestore.

    Is there a more efficient way of dealing with this? Like looping through all the images from the Firebase Storage and displaying them directly onto the RecyclerView?

    Yes, there is. You can use StorageReference#listAll() which:

    List all items (files) and prefixes (folders) under this StorageReference.

    This means that you can call the above method to list all files that exist at a particular location in your Storage bucket. In code, it will be as simple as

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search