0

I have a RecyclerView which uses a GridLayoutManager and each cell consists of a single ImageView. The data that i want to use to populate it are stored in my Firestore storage as .png and .jpeg images and the naming of each one is icon#.png or icon#.jpeg where # is the respective cell's position. My issue is that when i try to load each image into the respective cell's imageView with the way that you see below, i get an error message because i can't retrieve every image due to some having a .png extension while others have a .jpeg one. It's my understanding that i need to pass the file extension into the storageReference.child() method before i can load any image from Firestore, correct? So how can i achieve my goal here?

onBindViewHolder() :

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

    storageReference.child("Icons/icon"+position+".png").getDownloadUrl()
            .addOnSuccessListener(new OnSuccessListener<Uri>() {
                @Override
                public void onSuccess(Uri uri) {
                    GlideApp.with(mContext).load(uri).into(holder.iconImgView);
                    Log.d("Adapter", "Image loaded successfully");
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.d("Adapter", "ERROR DOWNLOADING IMAGE");
                }
            });
}

1 Answer 1

1

Not the smartest one but the easier method is to in onFailure method for fetching of*.png run the same fetch for *.jpeg. And only after that handle error.

This is in case you don't have something like 'exist(name)' method in Firestore (simply I'm not familiar with it)

Sign up to request clarification or add additional context in comments.

1 Comment

I've thought of that but i'm worried that even if the one fetch fails (and the other succeeds), they will both count towards the read limit set by Google thus cutting my reads in half

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.