New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to delete/remove PagedListAdapter item #281
Comments
I had same issue. |
@JiajunWong did you find any solution? |
i got this problem to when i try to Collections.sort |
I have created some custom adapter to handle this case(only a part of it actually). Luckily I was supposed to add on top of current list, so following solution only supports adding to top. However you can try to customize it. https://gist.github.com/guness/df12d8cc4f595af1395f4a1f5bca5f00 In addition, I think some kind of merging support for the data sources would be a nice to have feature for pagination library. |
i had same issue |
@yigit Can anyone answer this issue please. |
Already had this discussion here:
TL;DR: To update a pagedList you have to create a new list, this is how room update data and you have to do the same if you want to update your list. |
I try this after delete local data
|
After re-reading the documentation under Consider How Content Updates Work it appears the only way to have realtime updates is via implementing Room with the PagedList: If you're loading data directly from a Room database updates get pushed to your app's UI automatically. I'm planning to connect my Firestore queries to Room in order to be able to remove items from my PagedList without having to invalidate the DataSource and reload the entire RecyclerView. |
@AdamSHurwitz |
@abhinav272 This is not the case. When an individual item in Room is added or modified the PagedList updates the corresponding entry rather than refreshing all of the data in the component. Therefore I'm able to update Room with Firestore data when it changes and allow Room + PagedList to handle the updates on individual cells. As long as Room is updated of the change the PagedList will animate and update/add/remove the item modified. Conversely, if Firestore data was connected directly to the PagedList the entire data set would need to be invalidated / refreshed since the PagedList cannot automatically recognize individual changes from Firestore. |
@AdamSHurwitz When I create a DataSource which is fetching data from either Room or Network, it gives me a callback in onChanged() only once when the PagedList gets created (upon creation of DataSource) and when the pages are loaded it automatically gets displayed on UI.. Make sense? |
@abhinav272 - May you specify which onChangedd() method you are referring to? I don't make Room updates directly. I update Firestore's database. With Firestore when a piece of information changes the Firestore listener will send an update. I listen for that update and inform Room of the change using a LiveData object. This makes it easy to keep both my backend Firestore and front-end Room data synced with minimal work. |
I had the same kind of issue!!! Or else Do we have to implement in any other way??? |
@Dilip23 yeah, this looks fine. |
It worked !!! Great!!! |
@abhinav272 - This is how I am currently implementing it. When I remove an item from Firestore it also updates my Room Db. |
@faris-jameel if I understood correctly the question... |
@AdamSHurwitz @abhinav272 I have also implemented same way. Whenever I update the room DB, UI is notified with the new list and I call submitList() method. Whenever an item is added at last no problem, but if an item added at the top(as I am querying sorted list from DB) my whole list flickers(the whole list loaded again and whole list UI refreshed), same with remove, if I remove the last item its fine and only that item moves/affected but when top item, whole list seems loading again. |
@sonalchopra-vvdn |
I made a sample using PagedListAdapter https://github.com/roby222/recyclerViewSample |
@roby222 |
I would love to see an example of this using anything else then room. |
I need a sample that without |
need a sample that without room too. |
@guness Maybe you want to update the class with |
We're discussing options to better support granular updates in Paging3, but currently to delete / remove an item you'll need to update the backing db, then invalidate your |
In Paging3, we also provide APIs to transform a |
so there is just no way to update/modify a pagedlist item without invalidating the datasource if i am not using room. -_- |
Actually even with Room it works the exact same way, Room just handles the invalidation for you. Any modifications you make also need to update the source of truth for paging, because reloading the page should always keep the updates you make. For a |
I need a sample that without room too. |
Hello All, After Allot of search I fixed this bug. The answer is here bellow
|
This answer assumes that the list used in |
This won't work, you must remove items through Paging via invalidation, otherwise Paging will not know to carry your item removal through page reloads, refresh, config changes, etc. |
thanks , but the network data with pagingdata , snapshot is the pagingdata's copy. snapshot.toMutableList() , the mutablelist is the snapshot copy. |
ok , thanks |
If you are using only network call with pagging then this solution will work because you will remove Item locally after network api call . Let say I Call retrofit call first for removing the item and on success response of that Api Call we will remove that particular item from snapshot. |
snapshot is copy , delete from snapshot , the pagingData not change. |
Try this with the same code it is working. |
I have implemented PagingDataAdapter in my project and required multiple filtering and sorting. so any one could suggest me achive this. |
Is there any workaround for removing item from PagingDataAdapter ? @309152665 |
please help convert to java |
what if we are using cachedIn Flow? |
Currently I am using Android Architecture Components for App development everything is working along with paging library Now I want to remove recyclerview Item using PagedListAdapter to populate this we required to add a data source and from data source list is updating using LiveData no I want to remove a item from list notifyItemRemoved() is working from PagedList I am getting this exception:
java.lang.UnsupportedOperationException
java.util.AbstractList.remove(AbstractList.java:638)
The text was updated successfully, but these errors were encountered: