Reputation: 679
I have started implementation of Glide in my existing project and have been going through docs and examples. I checked sample app of Flickr and am trying to preload images just like it.
I am initialising GlideRequest in fragment and then passing it to the adapter to preload images and display. But when I run my app, I am neither getting any error nor are any images displayed. I have slightly modified my code from sample app as I don't want any model loader.
This is my initialisation in fragment:
private GlideRequests instructorRequestBuilder;
instructorRequestBuilder = GlideApp.with(this);
I assign in it to
preloadRequest
Variable in adapter's constructor.
Then following is the code into bindViewHolder:
private void setImage(final String image, final ImageView imageView)
{
preloadRequest.load(image)
.centerCrop()
.placeholder(R.drawable.placeholder_explore_user)
.error(R.mipmap.ic_launcher)
.listener(new RequestListener<Drawable>()
{
@Override public boolean onLoadFailed(@Nullable GlideException e, Object model,
Target<Drawable> target, boolean isFirstResource)
{
Log.d(TAG, "onLoadFailed: " + e);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target,
DataSource dataSource, boolean isFirstResource)
{
Log.d(TAG, "onLoadFailed: " + isFirstResource);
Log.d(TAG, "onLoadFailed: " + dataSource);
return false;
}
})
.into(imageView);
}
My adapter implements
ListPreloader.PreloadModelProvider
And this is the code for implemented methods:
@NonNull @Override public List<IConnectType> getPreloadItems(int position)
{
return iConnectInstructors.subList(position, position + 1);
}
@Nullable @Override
public RequestBuilder<Drawable> getPreloadRequestBuilder(@NonNull IConnectType item)
{
return preloadRequest.load(((User) item)
.getProfileImage250())
.placeholder(R.drawable.placeholder_explore_user)
.centerCrop()
.error(R.mipmap.ic_launcher);
}
PreloadSize and PreLoader are initialised as below:
ViewPreloadSizeProvider<IConnectType> preloadSizeProvider = new ViewPreloadSizeProvider<>();
RecyclerViewPreloader<IConnectType> preloader = new RecyclerViewPreloader<IConnectType>(
GlideApp.with(this), adapter,
preloadSizeProvider, 6);
rvInstructor.addOnScrollListener(preloader);
rvInstructor.setItemViewCacheSize(0);
Why is this not showing any items in the recyclerview?
Upvotes: 1
Views: 2237
Reputation: 679
It was an issue with the image size specified in viewholder. View holder was specified width and height of match_parent due to which image was not getting loaded. Even request listeners were failing, then I tried with submit()(as suggested here) and then realized that resources were loaded but loading them in view was failing.
Upvotes: 1
Reputation: 157
You are trying to load image in onbind view holder and its called when item is going to displayed so it delay in loading images...
Instead of this try to load all list of images in cache first. Then glide will automatically load from cache if its available in local cache.
This code snippet may help you....
https://github.com/bumptech/glide/issues/2499
Upvotes: 0