PagingData


public final class PagingData<T extends Object>


Container for Paged data from a single generation of loads.

Each refresh of data (generally either pushed by local storage, or pulled from the network) will have a separate corresponding PagingData.

Summary

Public methods

static final @NonNull PagingData<@NonNull T>
<T extends Object> empty()

Create a PagingData that immediately displays an empty list of items when submitted to a presenter.

static final @NonNull PagingData<@NonNull T>
<T extends Object> empty(
    @NonNull LoadStates sourceLoadStates,
    LoadStates mediatorLoadStates
)

Create a PagingData that immediately displays an empty list of items when submitted to a presenter.

static final @NonNull PagingData<@NonNull T>
<T extends Object> from(@NonNull List<@NonNull T> data)

Create a PagingData that immediately displays a static list of items when submitted to a presenter.

static final @NonNull PagingData<@NonNull T>
<T extends Object> from(
    @NonNull List<@NonNull T> data,
    @NonNull LoadStates sourceLoadStates,
    LoadStates mediatorLoadStates
)

Create a PagingData that immediately displays a static list of items when submitted to a presenter.

Extension functions

final @NonNull PagingData<@NonNull T>
<T extends Object> PagingDataFutures.filterAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull T, @NonNull Boolean> predicate,
    @NonNull Executor executor
)

Returns a PagingData containing only elements matching the given predicate.

final @NonNull PagingData<@NonNull R>
<T extends Object, R extends Object> PagingDataFutures.flatMapAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull T, @NonNull Iterable<@NonNull R>> transform,
    @NonNull Executor executor
)

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

final @NonNull PagingData<@NonNull R>
<T extends R, R extends Object> PagingDataFutures.insertSeparatorsAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull AdjacentItems<@NonNull T>, R> generator,
    @NonNull Executor executor
)

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

final @NonNull PagingData<@NonNull R>
<T extends Object, R extends Object> PagingDataFutures.mapAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull T, @NonNull R> transform,
    @NonNull Executor executor
)

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

final @NonNull PagingData<@NonNull T>
<T extends Object> PagingDataTransforms.filter(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Executor executor,
    @NonNull Function1<@NonNull T, @NonNull Boolean> predicate
)

Returns a PagingData containing only elements matching the given predicate.

final @NonNull PagingData<@NonNull R>
<T extends Object, R extends Object> PagingDataTransforms.flatMap(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Executor executor,
    @NonNull Function1<@NonNull T, @NonNull Iterable<@NonNull R>> transform
)

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

final @NonNull PagingData<@NonNull T>
<T extends Object> PagingDataTransforms.insertFooterItem(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull TerminalSeparatorType terminalSeparatorType,
    @NonNull T item
)

Returns a PagingData containing each original element, with the passed footer item added to the end of the list.

final @NonNull PagingData<@NonNull T>
<T extends Object> PagingDataTransforms.insertHeaderItem(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull TerminalSeparatorType terminalSeparatorType,
    @NonNull T item
)

Returns a PagingData containing each original element, with the passed header item added to the start of the list.

final @NonNull PagingData<@NonNull R>
<R extends Object, T extends R> PagingDataTransforms.insertSeparators(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull TerminalSeparatorType terminalSeparatorType,
    @NonNull Executor executor,
    @NonNull Function2<T, T, R> generator
)

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

final @NonNull PagingData<@NonNull R>
<T extends Object, R extends Object> PagingDataTransforms.map(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Executor executor,
    @NonNull Function1<@NonNull T, @NonNull R> transform
)

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

final @NonNull PagingData<@NonNull T>
<T extends Object> PagingRx.filterAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Single<@NonNull Boolean>> predicate
)

Returns a PagingData containing only elements matching the given predicate.

final @NonNull PagingData<@NonNull T>
<T extends Object> PagingRx.filterAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Single<@NonNull Boolean>> predicate
)

Returns a PagingData containing only elements matching the given predicate.

final @NonNull PagingData<@NonNull R>
<T extends Object, R extends Object> PagingRx.flatMapAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Single<@NonNull Iterable<@NonNull R>>> transform
)

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

final @NonNull PagingData<@NonNull R>
<T extends Object, R extends Object> PagingRx.flatMapAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Single<@NonNull Iterable<@NonNull R>>> transform
)

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

final @NonNull PagingData<@NonNull R>
<T extends R, R extends Object> PagingRx.insertSeparatorsAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Function2<T, T, @NonNull Maybe<@NonNull R>> generator
)

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

final @NonNull PagingData<@NonNull R>
<T extends R, R extends Object> PagingRx.insertSeparatorsAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Function2<T, T, @NonNull Maybe<@NonNull R>> generator
)

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

final @NonNull PagingData<@NonNull R>
<T extends Object, R extends Object> PagingRx.mapAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Single<@NonNull R>> transform
)

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

final @NonNull PagingData<@NonNull R>
<T extends Object, R extends Object> PagingRx.mapAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Single<@NonNull R>> transform
)

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

Public methods

empty

Added in 3.0.0
public static final @NonNull PagingData<@NonNull T> <T extends Object> empty()

Create a PagingData that immediately displays an empty list of items when submitted to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter and dispatches LoadState.NotLoading on all LoadStates to the presenter.

empty

Added in 3.2.0
public static final @NonNull PagingData<@NonNull T> <T extends Object> empty(
    @NonNull LoadStates sourceLoadStates,
    LoadStates mediatorLoadStates
)

Create a PagingData that immediately displays an empty list of items when submitted to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter.

Parameters
@NonNull LoadStates sourceLoadStates

LoadStates of PagingSource to pass forward to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter.

LoadStates mediatorLoadStates

LoadStates of RemoteMediator to pass forward to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter.

from

public static final @NonNull PagingData<@NonNull T> <T extends Object> from(@NonNull List<@NonNull T> data)

Create a PagingData that immediately displays a static list of items when submitted to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter and dispatches LoadState.NotLoading on all LoadStates to the presenter.

Parameters
@NonNull List<@NonNull T> data

Static list of T to display.

from

public static final @NonNull PagingData<@NonNull T> <T extends Object> from(
    @NonNull List<@NonNull T> data,
    @NonNull LoadStates sourceLoadStates,
    LoadStates mediatorLoadStates
)

Create a PagingData that immediately displays a static list of items when submitted to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter.

Parameters
@NonNull List<@NonNull T> data

Static list of T to display.

@NonNull LoadStates sourceLoadStates

LoadStates of PagingSource to pass forward to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter.

LoadStates mediatorLoadStates

LoadStates of RemoteMediator to pass forward to a presenter. E.g., androidx.paging.AsyncPagingDataAdapter.

Extension functions

PagingDataFutures.filterAsync

public final @NonNull PagingData<@NonNull T> <T extends Object> PagingDataFutures.filterAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull T, @NonNull Boolean> predicate,
    @NonNull Executor executor
)

Returns a PagingData containing only elements matching the given predicate.

Parameters
@NonNull AsyncFunction<@NonNull T, @NonNull Boolean> predicate

AsyncFunction returning false for unmatched items which should be filtered.

@NonNull Executor executor

Executor to run the AsyncFunction in.

PagingDataFutures.flatMapAsync

public final @NonNull PagingData<@NonNull R> <T extends Object, R extends Object> PagingDataFutures.flatMapAsync(
    @NonNull PagingData<@NonNull T> receiver,
    @NonNull AsyncFunction<@NonNull T, @NonNull Iterable<@NonNull R>> transform,
    @NonNull Executor executor
)

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

Parameters
@NonNull AsyncFunction<@NonNull T, @NonNull Iterable<@NonNull R>> transform

AsyncFunction to transform an item of type