Glide的.using方法无法使用FirebaseImageLoader解析

时间:2018-01-24 12:29:13

标签: android firebase firebase-storage firebaseui android-glide

我正在尝试从StorageReference加载Firebase Storage。我正在使用Glide库和FirebaseImageLoader中的FirebaseUI类。 .using方法无法解决。我认为这个问题与上下文有关。 homeTeam是我的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);
                }
            }
        });
    }


}
 // ...
}

1 个答案:

答案 0 :(得分:0)

看起来你正在使用Glide 4。

您需要创建一个扩展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());
    }
}

然后您可以像往常一样使用GlideApp加载图片。

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

阅读FirebaseUI Storage Readme doc了解更多信息

希望这会有所帮助:)