Reputation: 2789
The current architecture structure that I have for my Firebase storage is as follow:
Photos_folder/
-->users ID 01 --> profile_picture_folder/--> image/jpeg (URI)
-->users ID 02
-->users ID 03
--> ect...
In my adapter, I have an onBindViewHolder
method where I'm passing my URI
and retrieving the uri image through Firebase Storage network:
@Override
public void onBindViewHolder(@NonNull final CommentViewHolder holder, int position) {
Uri imageUri = Uri.parse(list.get(position).getImageUri());
photosStorageReference = FirebaseStorage.getInstance().getReference();
photosStorageReference.child(Constant.PHOTOS_FIREBASE).child(userId)
.child(Constant.USER_PROFILE_PICTURE_FOLDER).child(imageUri.getLastPathSegment())
.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
SimpleTarget target = new SimpleTarget<Bitmap> (200, 200) {
@Override
public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
imageView.setImageBitmap(bitmap);
}
};
GlideApp.with(context).asBitmap().load(uri).diskCacheStrategy(DiskCacheStrategy.DATA).apply(
RequestOptions.circleCropTransform()).into(target);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, e.getMessage());
}
});
}
PROBLEM:
Everything is working fine, however, onSuccess
method is doing the work in main thread and it's synchronous so the app is waiting between each image retrieval.
Is there anyway of achieving images retrieval from Firebase faster?
Maybe like establishing the connection to Firebase at a higher reference level, for example:
gs://appname-b4532.appspot.com/Photos/
After the connection is open, going over user ids and retrieving their respective image while going over sub path?
userId01/Profile_picture_folder/image_01
userId02/Profile_picture_folder/image_02
userId03/Profile_picture_folder/image_03
..ect
Upvotes: 0
Views: 720
Reputation: 317467
None of your work with Firebase here is actually synchronous, nor is it blocking the main thread. None of the Firebase SDKs provide blocking methods. Whenever you have a Task object, that work is being done on another thread.
Also, Glide works fully asynchronously - it does not block the thread that you used to invoke it.
Any delays you're seeing are just inherent in the system.
Upvotes: 2