Sobes.tech
Middle+

What methods must a subclass of PagingSource override in the Paging 2 library?

sobes.tech AI

Answer from AI

abstract class PagingSource<Key : Any, Value : Any> : PagingSource<Key, Value>() {

    /**
     * Request data for a page.
     * loadParams contains the page key and the number of items to load.
     * Returns LoadResult: Page (success) or Error (failure).
     */
    abstract fun load(params: LoadParams<Key>): LoadResult<Key, Value>

    /**
     * Gets the key for the next page upon invalidation of PagingSource.
     * anchorPosition - the position of the item visible to the user.
     * Returns the key for loading the next page or null if no loading is needed.
     */
    abstract fun getRefreshKey(state: PagingState<Key, Value>): Key?
}