Glide: How to use RecyclerViewPreloader with Glide 3.7.0 ?

Created on 10 May 2016  路  9Comments  路  Source: bumptech/glide

Dears,
I use Glide 3.7.0 . I want to preload images in recycler view . I don't find recycler view support in Glide 3.7.0

I tried to extract RecyclerViewPreloader from master branch but it gives me compilation error plus there is no example to use it with Glide v3.7.0

Please help

question

Most helpful comment

Thanks for reply but this didnt help me. it is the same like on master.

what i want is an example. I searched all internet and can't find example

I have a recycler view. how to prefetch images. I saw the link but don't know how to use it.

Appreciate your support. you will save me a lot of time. I was trying to build master branch inside my app but faced many dependancies

tried to use listView example with the class you mentioned. seems there is something missing

for example:

public RecyclerViewPreloader(RequestManager requestManager,
            PreloadModelProvider<T> preloadModelProvider,
            PreloadSizeProvider<T> preloadDimensionProvider, int maxPreload) {

        ListPreloader<T> listPreloader = new ListPreloader<>(preloadModelProvider,
                preloadDimensionProvider, maxPreload);
        recyclerScrollListener = new RecyclerToListViewScrollListener(listPreloader);
    }

why it takes request manager and doesn't use it ?

also where is the PreloadModelProvider ?

please give me full example to help me

All 9 comments

The API changed between 4.0 and 3.x, but it seems I did backport this earlier for some reason:
https://github.com/TWiStErRob/glide-support/tree/master/src/glide3/thirdparty/com/bumptech/glide/integration/recyclerview
Though there's no actual usage of this, it should be the same/very close to the usages on master. Please tell me how these classes perform with 3.7 :)

Thanks for reply but this didnt help me. it is the same like on master.

what i want is an example. I searched all internet and can't find example

I have a recycler view. how to prefetch images. I saw the link but don't know how to use it.

Appreciate your support. you will save me a lot of time. I was trying to build master branch inside my app but faced many dependancies

tried to use listView example with the class you mentioned. seems there is something missing

for example:

public RecyclerViewPreloader(RequestManager requestManager,
            PreloadModelProvider<T> preloadModelProvider,
            PreloadSizeProvider<T> preloadDimensionProvider, int maxPreload) {

        ListPreloader<T> listPreloader = new ListPreloader<>(preloadModelProvider,
                preloadDimensionProvider, maxPreload);
        recyclerScrollListener = new RecyclerToListViewScrollListener(listPreloader);
    }

why it takes request manager and doesn't use it ?

also where is the PreloadModelProvider ?

please give me full example to help me

Good points :) I think I wanted to use it for something, copied it, made it compile, and added that unused suppress to early so I didn't notice RM not being used.

Added a full example for you (see commit above), here's an excerpt:

PreloadingAdapter adapter = new PreloadingAdapter(Glide.with(this), ...);
list.addOnScrollListener(new RecyclerViewPreloader<>(adapter, adapter, 5));

private static class PreloadingAdapter extends RecyclerView.Adapter<SimpleViewHolder>
        implements PreloadModelProvider<String>, PreloadSizeProvider<String> {
    private final GenericRequestBuilder<String, ?, ?, ?> glide;
    private int[] stolenSize;

    public PreloadingAdapter(RequestManager glide, List<String> urls) {
        this.urls = urls;
        this.glide = glide.fromString();
    }

    @Override public void onBindViewHolder(SimpleViewHolder holder, int position) {
        Target<?> target = glide.load(url).into(holder.imageView);
        if (stolenSize == null) {
            // assuming uniform sizing among items (fixed size or match works, wrap doesn't)
            target.getSize(new SizeReadyCallback() {
                @Override public void onSizeReady(int width, int height) {
                    if (0 < width && 0 < height) {
                        stolenSize = new int[] {width, height};
                    }
                }
            });
        }
    }
    @Override public List<String> getPreloadItems(int position) {
        return Collections.singletonList(getItem(position));
    }
    @Override public GenericRequestBuilder getPreloadRequestBuilder(String item) {
        return glide.load(item);
    }
    @Override public int[] getPreloadSize(String item, int adapterPosition, int perItemPosition) {
        return stolenSize;
    }
}

Hi Rob.
Can you show me how to add this RecyclerViewPreloader to use with 3.7.0. ?
I tried to copy code and add it to my project but I'm getting
Error:(85, 42) error: cannot infer type arguments for ListPreloader<>

Thanks in advance.

@rule-po Are you using the ones mentioned here https://github.com/bumptech/glide/issues/1189#issuecomment-218017999?

@TWiStErRob Yes, I have used those and it that is error I got.
Any suggestion how to add it to code would be appreciated.

There's an actual usage example in that repo as well:
https://github.com/TWiStErRob/glide-support/commit/92b40e9ef64c964eb43b329aaae56d8f0a19706e
(ignore the gradle 4.0.0 update, that's unrelated)

@TWiStErRob I tried that too, but it doesn't work.
Error:Failed to resolve: com.github.bumptech.glide:recyclerview-integration:2.0.0-SNAPSHOT

@rule-po https://github.com/bumptech/glide/wiki/Snapshots, but you probably don't need that, because it's for 4.0 and you're using 3.7. Look at my build.gradle, it should be clear which deps are for v3 and v4.

Was this page helpful?
0 / 5 - 0 ratings