Good morning everyone, I have to find a way to han...
# rx
s
Good morning everyone, I have to find a way to handle this logic : Step 1: get data from cache -> show on UI Step 2: call APIs and update cache Step 3: update UI with lasted Data -> so which way simplify can do it for updating UI? Thanks.
r
What have you tried?
s
What have you tried?
1. I have get data from Room and show it to UI 2. Call API with
Zip
get Data from Network and save the result to Room 3. Update lasted data to UI again. => so I want to combine 3 steps to one function/stream.
s
How about not combining them at all? 1. Observe data from Room. If you use Flowable<Data> then you'll get updates automatically as the DB changes. 2. Separately, call the API and save the result to Room.
s
@StavFX thank for your advice, but what happen on database if I have some event to update/insert? Is it notify 1 item or the whole item list to UI I have built a chat app, so do you have any prefer sources/solution for it?
s
I think they way Room works (I might be wrong) is that if anything changes in the DB (update/insert/delete), you will get the answer to your query again - so the full list, even if it's identical to the last list and your query wasn't really affected by the triggering update/insert/delete. So you can use something like
distinctUntilChanged
to make sure you are not propagating duplicate data to the ui. And you can use DiffUtils to load the full list into the UI without "reloading" the entire recyclerview (or whatever the ui layer is doing with the data). Having said all that, I've never actually built a chat-like feature and there might be a better way to do this (the Paging 2/3 library might be worth looking into)
r
Just one small correction, if anything changes in the tables involved in a query, the query is re-run