This is my first time using Paging library 3. This is my PagingSource file, For the API we have to use a cursor in order to do paging, every time I refresh the adapter it scrolls back to the top of the list, is there any way to refresh the list without scrolling to the top?
class SearchProductDataSource(
private val searchFilter: SearchFilter,
private val searchProductsUseCase: SearchProductsUseCase
) : PagingSource<String, Product>() {
override fun getRefreshKey(state: PagingState<String, Product>): String? {
return null
}
override suspend fun load(params: LoadParams<String>): LoadResult<String, Product> {
try {
val currentKey = params.key
val newFilter: SearchFilter = searchFilter.copy(afterCursor = currentKey)
val result = searchProductsUseCase(newFilter, params.loadSize)
val nextKey = if (result?.pageInfo?.hasNextPage == true)
result.cursor
else
null
return LoadResult.Page(result.list, currentKey, nextKey)
} catch (e: Exception) {
Timber.e(e)
return LoadResult.Error(e)
}
}
}
This is how I call a refresh method after updating the wishlist.
adapter.refresh()