Status Update
Comments
cc...@google.com <cc...@google.com> #2
To remove an item, you can do one of a few things:
1) Remove it at the DataSource.Factory level. You can potentially wrap your DataSource.Factory with another, which will hold items in memory. Then route modifications to modify the in-memory copy in your wrapper source.
This is probably a lot of code to do it this way.
2) Remove it at the adapter level. Use AsyncPagedListDiffer, and intercept events going to the adapter to act as though the item is missing (e.g. report size = pagedList.size -1 , wrap get() to do:
index = index < removeIndex ? index : index - 1
It's a lot of possibilities for off by one errors, but this is the approach I'd generally recommend (if you don't want to do the two below).
3) Use a database to make local modifications to data that comes from network, and page from the database (this is generally what Paging expects, but if you're not using a database I know it could be a lot of code)
4) Wait for paging 3.0 in a couple months or so, which is planned to support filtering items, essentially:
liveDataPagedList.map { pagedList.filter { !myRemovedItems.contains(it) } }
ku...@gmail.com <ku...@gmail.com> #3
3.0.0 is almost here.
Regarding filter, don't we still have to reload the data for it?
-
Load the list of items liveDataPagedList.map { pagedList.filter { !myRemovedItems.contains(it) } }
-
Remove a specific item itemDao.removeItem(item)
-
Update the PagedList dataSource.invalidate()
How do we let the PagedList know that just a specific item has been removed? We still need it to reload so it can have the data and do it's filtering.
Can we have a PagedList.remove(item: T) and an PagedList.update(item: T)?
cc...@google.com <cc...@google.com> #4
flowPagingData
.cachedIn(viewModelScope)
.combine(flowOfRemovedItems)
.flatMapLatest(flowOfRemovedItems) { pagingData, removedItems ->
pagingData.filter { !removedItems.contains(it) }
}
any operations that occur after 'cachedIn' will allow downstream collection to reuse previously loaded data (including any transforms that happened prior to the cache operation). This pattern can also be used for any updated items, by using 'map' instead of 'filter'.
ku...@gmail.com <ku...@gmail.com> #5
Thanks for the reply. That makes sense. I did something like that on the adapter level which tracks the positions and items corresponding to those positions both for removed and updated items.
Looking forward to 3.0!
Description
Iam using paging library.so data loaded from network, i cannot remove particular item from paging list.
i get unsupported operation exception.
kindly tell me how resolve the issue.