Hot questions for Using Glide in firebaseui

Question:

There are tons of duplicated answers I had tried almost all of them but I am still not able to use Firebase storage image with Glide.

First of all I am using docs

    FirebaseStorage storage  = FirebaseStorage.getInstance();
    StorageReference storageRef = storage.getReference();
    StorageReference pathReference = storageRef.child("sorular/1.jpg");

   // ImageView in your Activity
   ImageView imageView = rootView.findViewById(R.id.imageView);

   // Load the image using Glide
   Glide.with(this /* context */)
        .using(new FirebaseImageLoader()) // Cannot resolve method 'using
        .load(pathReference)
        .into(imageView);

if I clean the .using part of Glide, logcat it gives this error:

E/GlideExecutor: Request threw uncaught throwable com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: gs://123...appspot.com/sorular/1.jpg at com.bumptech.glide.Registry.getModelLoaders(Registry.java:227) at com.bumptech.glide.load.engine.DecodeHelper.getLoadData(DecodeHelper.java:179) at com.bumptech.glide.load.engine.DecodeHelper.getCacheKeys(DecodeHelper.java:197) at com.bumptech.glide.load.engine.ResourceCacheGenerator.startNext(ResourceCacheGenerator.java:41) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:282) at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:249) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:222) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:347)

So how can use firebase storage images in my android app in a best way?

also this my build gradle dependencies:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:palette-v7:27.0.2'
    implementation "com.android.support:cardview-v7:27.0.2"
    implementation "com.android.support:recyclerview-v7:27.0.2"
    implementation "com.android.support:support-v4:27.0.2"
    implementation 'com.android.support:design:27.0.2'

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.github.florent37:materialviewpager:1.2.3'


    implementation 'com.google.firebase:firebase-database:11.8.0'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.firebaseui:firebase-ui-storage:2.0.1'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Answer:

Change this:

 implementation 'com.firebaseui:firebase-ui-storage:2.0.1'

to this:

  implementation 'com.firebaseui:firebase-ui-storage:3.2.1'

According to the Glide docs:

using()

The using() API was removed in Glide 4 to encourage users to register their components once with a AppGlideModule to avoid object re-use. Rather than creating a new ModelLoader each time you load an image, you register it once in an AppGlideModule and let Glide inspect your model (the object you pass to load()) to figure out when to use your registered ModelLoader.

To make sure you only use your ModelLoader for certain models, implement handles() as shown above to inspect each model and return true only if your ModelLoader should be used.

using() was removed from Glide 4.

To Solve this, you need to do this: To load an image from a StorageReference, first register an AppGlideModule:

  @GlideModule
public class MyAppGlideModule extends AppGlideModule {

@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
    // Register FirebaseImageLoader to handle StorageReference
    registry.append(StorageReference.class, InputStream.class,
            new FirebaseImageLoader.Factory());
  }
}

Once you have created an AppGlideModule class and done a clean build, you can use GlideApp to load a StorageReference into an ImageView:

// Reference to an image file in Cloud Storage
StorageReference storageReference = ...;

// ImageView in your Activity
ImageView imageView = ...;

// Download directly from StorageReference using Glide
// (See MyAppGlideModule for Loader registration)
GlideApp.with(this /* context */)
        .load(storageReference)
        .into(imageView);

more info here: https://github.com/firebase/FirebaseUI-Android/tree/master/storage

Question:

All in all I want to store and retrieve a profile picture for each user in Firebase. I am trying to retrieve the image from Firebase using FirebaseUI and Glide (as explained here).

It works perfectly for what I want to achieve, but I want to handle the case when the user didn't upload his own profile picture (when there is no picture in the Firebase storage). Sadly I am not able to find how to check if there is such a file in the Firebase storage. Does anyone have an idea how to check if there is a file profile.jpg

(in Firebase storage) in the following code?

StorageReference storageRef =  storageReference.child("profile.jpg");

ImageView imageView = profilePicture;
// Load the image using Glide
Glide.with(context /* context */)
     .using(new FirebaseImageLoader())
     .load(storageRef)
     .into(imageView);

Answer:

To show default picture if there is no 'profile.jpg' on firebase, in newer v4 Glide, you can use RequestOptions, like this:

RequestOptions options = new RequestOptions().error(R.drawable.default_avatar);
Glide.with(context /* context */)
         .using(new FirebaseImageLoader())
         .load(storageRef)
         .apply(options)
         .into(imageView);
Original answer for Glide v3

Use error method:

Glide.with(context /* context */)
     .using(new FirebaseImageLoader())
     .load(storageRef)
     .error(R.drawable.default_avatar)
     .into(imageView);