How to observe changed items from Room with Paging 3 library in Android

Viewed 587

I have a list of data which is loading by using PagingSource.

Here is my code in DAO:

  @Query("SELECT * FROM Transport")
  fun getAllTransportsPaged(): PagingSource<Int, Transport>

I am getting the paged data with a Flow with this:

Pager(config = PagingConfig(
          pageSize = 100,
          enablePlaceholders = true,
      )) {
        transportsDao.getAllTransportsPaged()
      }.flow
       .cachedIn(viewModelScope + Dispatchers.IO)

I have another function which is updating an item in a local database:

@Query("UPDATE Transport SET favorite = :favorite WHERE id = :id")
suspend fun changeFavorite(id: Int, favorite: Boolean)

After calling this function the whole data in the list is starting to load from the beginning.

Is there a way to get only changed data with paging library?

0 Answers
Related