0
我正嘗試使用Glide從服務器加載圖像。但問題是動態的URL我每次打開頁面時,它從服務器Glide更改動態url的緩存鍵
加載相同的圖像,這是我的代碼
@android.databinding.BindingAdapter("imageurl")
public static void loadImageFromUrl(ImageView imageView, String url) {
if (url == null || url.isEmpty()) return;
GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder()
.addHeader("Authorization", "Bearer " + NetworkConstant.TOKEN).build());
View parent = imageView.getRootView();
final ProgressBar progressBar = (ProgressBar) parent.findViewById(R.id.progressBar);
Glide.with(imageView.getContext()).load(glideUrl).listener(new RequestListener<GlideUrl, GlideDrawable>() {
@Override
public boolean onException(Exception e, GlideUrl model, Target<GlideDrawable> target, boolean isFirstResource) {
Log.e("Error", e.getMessage());
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, GlideUrl model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
Log.e("IsFromCache", isFromMemoryCache + " : firstResource" + isFirstResource);
if (progressBar != null && progressBar.getVisibility() == View.VISIBLE) {
progressBar.setVisibility(View.GONE);
}
return false;
}
})
.fitCenter()
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
}