问题
I am trying to set up all my lists using new Android Architecture Components: Room Persistance Library and Paging Library. But I am facing the following problem. Imagine an app that has a lots of diferents lists of the same model. Each list has his own url request to server. Some elements can be repeated in diferent responses. So I think that I have to insert and update all elements of each response to a table of that model. Furthermore, each request has pages. For example, elements/famous/0
, elements/famous/1
. So, when page 1 response is received the list containing the elements of list 0 have to add the elements returned by page 1.
A Room request that returns a LivePagedListProvided is like this:
@Query("SELECT * FROM elements")
fun getElements(): LivePagedListProvider<Int, Model>
When some element of the query changes, or an element added to the database affects de query, the LivePagedListProvider
observables provide a change, so the UI changes automatically.
The question is: how should I save and retrieve elements that can be contained in differents lists depending on diferent requests using Paging Library?
回答1:
If you use only one table for local storage of your received data (from different requests to the server), so after each updating this table, all your DataSources will be invalidated, so thats why we see autoupdating. For different requests you can use different tables, but this is a not good)
I think you can write select query
with some conditions, which represent difference between you requests to the server, if the result model same in those requests.
来源:https://stackoverflow.com/questions/47203992/paging-library-and-room-with-different-pagedlists-that-depends-of-different-requ