0

I'm trying to load a StorageReference from Firebase Storage. I'm using the Glide library and the FirebaseImageLoader class from the FirebaseUI. The .using method fails to resolve. I think the problem is something to do with the context. homeTeam is my ImageView.

public class MatchAdapter extends FirestoreAdapter<MatchAdapter.ViewHolder> {
//......


static class ViewHolder extends RecyclerView.ViewHolder {
    private Context mContext;


    @BindView(R.id.imageView)
    ImageView homeTeam;

    @BindView(R.id.imageView2)
    ImageView awayTeam;

    @BindView(R.id.textView)
    TextView score;

    @BindView(R.id.textView2)
    TextView competition;

    @BindView(R.id.textView3)
    TextView game;

    public ViewHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);
    }
    public void bind(final DocumentSnapshot snapshot,
                     final OnMatchSelectedListener listener) {

        Match match = snapshot.toObject(Match.class);
        Resources resources = itemView.getResources();

        Glide.with(mContext)
                .using(new FirebaseImageLoader())
                .load(match.getHomeTeam())
                .into(homeTeam);
        Glide.with(awayTeam.getContext())
                .load(match.getAwayTeam())
                .into(awayTeam);


        score.setText(match.getScore());
        competition.setText(match.getCompetition());
        game.setText(match.getGame());





        // Click listener
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onMatchSelected(snapshot);
                }
            }
        });
    }


}
 // ...
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
flutter
  • 6,188
  • 9
  • 45
  • 78

1 Answers1

0

It looks like you're using Glide 4.

You need to create a class that extends 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());
    }
}

and then you can use GlideApp to load the image as usual.

GlideApp.with(this /* context */)
        .load(storageReference)
        .into(imageView);

Read FirebaseUI Storage Readme doc for more information

Hope this helps :)

Wilik
  • 7,630
  • 3
  • 29
  • 35