StaticListPagingSourceFactoryKt

Added in 3.2.0

public final class StaticListPagingSourceFactoryKt


Summary

Public methods

static final @NonNull PagingSourceFactory<@NonNull Integer, @NonNull Value>
@VisibleForTesting
<Value extends Object> asPagingSourceFactory(@NonNull List<@NonNull Value> receiver)

Returns a PagingSourceFactory that creates PagingSource instances.

static final @NonNull PagingSourceFactory<@NonNull Integer, @NonNull Value>
@VisibleForTesting
<Value extends Object> asPagingSourceFactory(
    @NonNull Flow<@NonNull List<@NonNull Value>> receiver,
    @NonNull CoroutineScope coroutineScope
)

Returns a PagingSourceFactory that creates PagingSource instances.

Public methods

asPagingSourceFactory

@VisibleForTesting
public static final @NonNull PagingSourceFactory<@NonNull Integer, @NonNull Value> <Value extends Object> asPagingSourceFactory(@NonNull List<@NonNull Value> receiver)

Returns a PagingSourceFactory that creates PagingSource instances.

Can be used as the pagingSourceFactory when constructing a Pager in tests. The same factory should be reused within the lifetime of a ViewModel.

Extension method on a List of data from which a PagingSource will load from. While this factory supports multi-generational operations such as REFRESH, it does not support updating the data source. This means any PagingSources generated by the same factory will load from the exact same list of data.

asPagingSourceFactory

@VisibleForTesting
public static final @NonNull PagingSourceFactory<@NonNull Integer, @NonNull Value> <Value extends Object> asPagingSourceFactory(
    @NonNull Flow<@NonNull List<@NonNull Value>> receiver,
    @NonNull CoroutineScope coroutineScope
)

Returns a PagingSourceFactory that creates PagingSource instances.

Can be used as the pagingSourceFactory when constructing a Pager in tests. The same factory should be reused within the lifetime of a ViewModel.

Extension method on a Flow of list that represents the data source, with each static list representing a generation of data from which a PagingSource will load from. With every emission to the flow, the current PagingSource will be invalidated, thereby triggering a new generation of Paged data.

Supports multiple factories and thus multiple collection on the same flow.

Parameters
@NonNull CoroutineScope coroutineScope

the CoroutineScope to collect from the Flow of list.