I have a list of files, which get a remote thumbnail.
If I click on the file, a better image gets downloaded (depending on screen size).
So my idea is while downloading the better image to show the thumbnail.
I only can do this via
GlideApp.with(context)
.load(container)
.placeholder(defaultImage)
.into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get();
which may not be done in main task.
However using this image as a placeholder to download the real image
GlideApp.with(context)
.load(container)
.placeholder(drawable)
.error(drawable)
.into(view);
needs to be done on main ui thread.
Best would be to have the possibility to specify an image key as placeholder.
I found this is working for me.
However, if for some reason there is no thumbnail, then first the thumbnail will be downloaded and only after that the resized image will be downloaded.
So this is still not perfect…
GlideApp
.with(getContext())
.asBitmap()
.load(thumbnail)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
mImageView.setImageBitmap(resource);
GlideApp.with(getContext())
.asBitmap()
.load(resizedImage)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
mImageView.setImageBitmap(resource);
}
}
);
}
}
);
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
It's not safe to use one Glide load as the placeholder for another because Glide may recycle the "placeholder" resource at any time.
Instead use the thumbnail API for the same purpose: http://bumptech.github.io/glide/doc/options.html#thumbnail-requests
Thank you for the hint!
working for me:
GlideApp.with(context)
.load(url)
.thumbnail(GlideApp.with(context).load(url).onlyRetrieveFromCache(true),
GlideApp.with(context).load(placeHolder))
.error(placeHolder)
.into(this)
Most helpful comment
It's not safe to use one Glide load as the placeholder for another because Glide may recycle the "placeholder" resource at any time.
Instead use the thumbnail API for the same purpose: http://bumptech.github.io/glide/doc/options.html#thumbnail-requests