I'm using Paging 3 with a local database using Room, the @Query from Room is the following:
@Query("SELECT * FROM Channel LIMIT :limit OFFSET :offset")
suspend fun getAllChannels(limit: Int, offset: Int): List<Channel>
Then i get my data in the PagingSource like this, and return the LoadResult.Page with my data
channels = channelDao.getAllChannels(
params.loadSize,
position * params.loadSize
)
return LoadResult.Page(
data = channels,
prevKey = if (position == INITIAL_INDEX) null else position - 1,
nextKey = if (mData.isEmpty()) null else position + 1
)
in my repository, i get the channels like this:
override fun getAllChannels(): Flow<PagingData<Channel>> {
return Pager(
PagingConfig(
pageSize = 20,
enablePlaceholders = false,
initialLoadSize = 20
)
) {
ChannelPagingSource(
channelDao
)
}.flow
}
The problem with this approach is that my view can't observe any modifications happening on the Channel objects, so if it gets updated there's no way to be notified. Is it possible to get observable objects using pagination?
An alternative way is to drop the paging and just return a Flow<List> from Room and consume it, but it's heavy and slowing down the app a little.