mapPagingData

fun <D : IviDataSource<E, Q>, E : Any, Q : Any> Flow<D>.mapPagingData(    pagingConfig: PagingConfig,     query: Q,     lifecycleOwner: LifecycleOwner): Flow<PagingData<E>>

Transforms a IviDataSource into a PagingData with a given pagingConfig and query.

A Pager is created for each emitted IviDataSource. See Pager for more information.

The lifecycleOwner needs to stay active as long as the returns Flow is used.

Use PagingData.map to transform the returned E to another PagingData type.

Example usages:

val dataSourceLiveData: LiveData<IviDataSource<Contact, ContactDataSourceQuery>> = ...
val pagingConfig: PagingConfig = ...
val query: ContactDataSourceQuery = ...
val contactViewModelPagingData: Flow<PagingData<ContactViewModel>> =
dataSourceLiveData.mapToPagingData(pagingConfig, query, lifecycleOwner)
.map { pagingData ->
pagingData.map { contact ->
ContactViewModel(contact)
}
}

The same mapPagingData extension exist for an IviDataSource. If you do not plan to use a RecyclerView to present the data, use mapQuery instead.


fun <D : IviDataSource<E, Q>, E : Any, Q : Any> Flow<D>.mapPagingData(    pagingConfig: PagingConfig,     queries: Collection<Q>,     lifecycleOwner: LifecycleOwner): Flow<PagingData<E>>

Transforms a IviDataSource into a PagingData with a given pagingConfig and queries. The result of the queries are concatenated after each other.

A Pager is created for each emitted IviDataSource. See Pager for more information.

The lifecycleOwner needs to stay active as long as the returns Flow is used.

Use PagingData.map to transform the returned E to another PagingData type.

Example usages:

val dataSourceFlow: Flow<IviDataSource<Contact, ContactDataSourceQuery>> = ...
val pagingConfig: PagingConfig = ...
val query1: ContactDataSourceQuery = ...
val query2: ContactDataSourceQuery = ...
val contactViewModelPagingData: Flow<PagingData<ContactViewModel>> =
dataSourceFlow.mapToPagingData(pagingConfig, listOf(query1, query2), lifecycleOwner)
.map { pagingData ->
pagingData.map { contact ->
ContactViewModel(contact)
}
}

Note: All IviPagingSource implementations used in the queries must support placeholders. See IviPagingSource.LoadResult.Page for details. The PagingConfig.enablePlaceholders of pagingConfig must be true.


fun <D : IviDataSource<E, Q>, E : Any, Q : Any> LiveData<D>.mapPagingData(    pagingConfig: PagingConfig,     query: Q,     lifecycleOwner: LifecycleOwner): Flow<PagingData<E>>

Transforms a IviDataSource into a PagingData with a given pagingConfig and query.

A Pager is created for each emitted IviDataSource. See Pager for more information.

The lifecycleOwner needs to stay active as long as the returned Flow is used.

Use PagingData.map to transform the returned E into another PagingData type.

Example usage:

val dataSourceFlow: Flow<IviDataSource<Contact, ContactDataSourceQuery>> = ...
val pagingConfig: PagingConfig = ...
val query: ContactDataSourceQuery = ...
val contactViewModelPagingData: Flow<PagingData<ContactViewModel>> =
dataSourceFlow.mapPagingData(pagingConfig, query, lifecycleOwner)
.map { pagingData ->
pagingData.map { contact ->
ContactViewModel(contact)
}
}

The same mapPagingData extension exists for an IviDataSource. If you do not plan to use a RecyclerView to present the data, use mapQuery instead.


fun <D : IviDataSource<E, Q>, E : Any, Q : Any> LiveData<D>.mapPagingData(    pagingConfig: PagingConfig,     queries: Collection<Q>,     lifecycleOwner: LifecycleOwner): Flow<PagingData<E>>

Transforms a IviDataSource into a PagingData with a given pagingConfig and queries. The result of the queries are concatenated after each other.

A Pager is created for each emitted IviDataSource. See Pager for more information.

The lifecycleOwner needs to stay active as long as the returns Flow is used.

Use PagingData.map to transform the returned E to another PagingData type.

Example usages:

val dataSourceLiveData: LiveData<IviDataSource<Contact, ContactDataSourceQuery>> = ...
val pagingConfig: PagingConfig = ...
val query1: ContactDataSourceQuery = ...
val query2: ContactDataSourceQuery = ...
val contactViewModelPagingData: Flow<PagingData<ContactViewModel>> =
dataSourceLiveData.mapPagingData(pagingConfig, listOf(query1, query2), lifecycleOwner)
.map { pagingData ->
pagingData.map { contact ->
ContactViewModel(contact)
}
}

Note: All IviPagingSource implementations used in the queries must support placeholders. See IviPagingSource.LoadResult.Page for details. The PagingConfig.enablePlaceholders of pagingConfig must be true.