Class RecyclerViewPreloader<T>

  • Type Parameters:
    T - The type of the model being displayed in the RecyclerView.

    public final class RecyclerViewPreloader<T>
    extends androidx.recyclerview.widget.RecyclerView.OnScrollListener
    Loads a few resources ahead in the direction of scrolling in any RecyclerView so that images are in the memory cache just before the corresponding view in created in the list. Gives the appearance of an infinitely large image cache, depending on scrolling speed, cpu speed, and cache size.

    Must be added as a listener to the RecyclerView using RecyclerView.addOnScrollListener(RecyclerView.OnScrollListener), or have its corresponding methods called from another RecyclerView.OnScrollListener to function.

    This class only works with LinearLayoutManager and subclasses of LinearLayoutManager.

    • Constructor Summary

      Constructors 
      Constructor Description
      RecyclerViewPreloader​(android.app.Activity activity, com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider, com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider, int maxPreload)
      Helper constructor that accepts an Activity.
      RecyclerViewPreloader​(android.app.Fragment fragment, com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider, com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider, int maxPreload)
      Deprecated.
      Use constructor RecyclerViewPreloader(Fragment, PreloadModelProvider, PreloadSizeProvider) instead.
      RecyclerViewPreloader​(androidx.fragment.app.FragmentActivity fragmentActivity, com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider, com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider, int maxPreload)
      Helper constructor that accepts an FragmentActivity.
      RecyclerViewPreloader​(androidx.fragment.app.Fragment fragment, com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider, com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider, int maxPreload)
      Helper constructor that accepts an Fragment.
      RecyclerViewPreloader​(com.bumptech.glide.RequestManager requestManager, com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider, com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider, int maxPreload)
      Constructor that accepts interfaces for providing the dimensions of images to preload, the list of models to preload for a given position, and the request to use to load images.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void onScrolled​(androidx.recyclerview.widget.RecyclerView recyclerView, int dx, int dy)  
      • Methods inherited from class androidx.recyclerview.widget.RecyclerView.OnScrollListener

        onScrollStateChanged
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RecyclerViewPreloader

        public RecyclerViewPreloader​(@NonNull
                                     android.app.Activity activity,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider,
                                     int maxPreload)
        Helper constructor that accepts an Activity.
      • RecyclerViewPreloader

        public RecyclerViewPreloader​(@NonNull
                                     androidx.fragment.app.FragmentActivity fragmentActivity,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider,
                                     int maxPreload)
        Helper constructor that accepts an FragmentActivity.
      • RecyclerViewPreloader

        public RecyclerViewPreloader​(@NonNull
                                     androidx.fragment.app.Fragment fragment,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider,
                                     int maxPreload)
        Helper constructor that accepts an Fragment.
      • RecyclerViewPreloader

        @Deprecated
        public RecyclerViewPreloader​(@NonNull
                                     android.app.Fragment fragment,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider,
                                     int maxPreload)
        Deprecated.
        Use constructor RecyclerViewPreloader(Fragment, PreloadModelProvider, PreloadSizeProvider) instead.
        Helper constructor that accepts an Fragment.
      • RecyclerViewPreloader

        public RecyclerViewPreloader​(@NonNull
                                     com.bumptech.glide.RequestManager requestManager,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadModelProvider<T> preloadModelProvider,
                                     @NonNull
                                     com.bumptech.glide.ListPreloader.PreloadSizeProvider<T> preloadDimensionProvider,
                                     int maxPreload)
        Constructor that accepts interfaces for providing the dimensions of images to preload, the list of models to preload for a given position, and the request to use to load images.
        Parameters:
        preloadModelProvider - Provides models to load and requests capable of loading them.
        preloadDimensionProvider - Provides the dimensions of images to load.
        maxPreload - Maximum number of items to preload.
    • Method Detail

      • onScrolled

        public void onScrolled​(androidx.recyclerview.widget.RecyclerView recyclerView,
                               int dx,
                               int dy)
        Overrides:
        onScrolled in class androidx.recyclerview.widget.RecyclerView.OnScrollListener