AsyncListUtil

open class AsyncListUtil<T>(source)

A utility class that supports asynchronous content loading.

It can be used to load Cursor data in chunks without querying the Cursor on the UI Thread while keeping UI and cache synchronous for better user experience.

It loads the data on a background thread and keeps only a limited number of fixed sized chunks in memory at all times.

AsyncListUtil queries the currently visible range through ViewCallback, loads the required data items in the background through DataCallback, and notifies a ViewCallback when the data is loaded. It may load some extra items for smoother scrolling.

Note that this class uses a single thread to load the data, so it suitable to load data from secondary storage such as disk, but not from network.

This class is designed to work with RecyclerView, but it does not depend on it and can be used with other list views.

Constructors

Link copied to clipboard
constructor(@NonNull klass: Class<T>, tileSize: Int, @NonNull dataCallback: AsyncListUtil.DataCallback<T>, @NonNull viewCallback: AsyncListUtil.ViewCallback)
Creates an AsyncListUtil.

Types

Link copied to clipboard
abstract class DataCallback<T>
The callback that provides data access for AsyncListUtil.
Link copied to clipboard
abstract class ViewCallback
The callback that links AsyncListUtil with the list view.

Functions

Link copied to clipboard
open fun getItem(position: Int): T
Returns the data item at the given position or null if it has not been loaded yet.
Link copied to clipboard
open fun getItemCount(): Int
Returns the number of items in the data set.
Link copied to clipboard
open fun onRangeChanged()
Updates the currently visible item range.
Link copied to clipboard
open fun refresh()
Forces reloading the data.