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?
@Insert suspend fun addTransport(vararg transport: Transport)
– SmallmanFlow<PagingData>
for your adapter? Room's PagingSource already has built-in support to resume where it left off after invalidation, so there must be some drastic changes happening in your DB or you might be on an old version of Paging? Can you also share your DiffUtil implementation? That could be another possibility for Paging to not understand rows that are supposed to be equal – Breastpinclass TransportsDiffCallback : DiffUtil.ItemCallback<Transport>() { override fun areItemsTheSame(oldItem: Transport, newItem: Transport): Boolean = oldItem.id == newItem.id override fun areContentsTheSame(oldItem: Transport, newItem: Transport): Boolean = oldItem == newItem }
– Smallman