https://kotlinlang.org logo
#compose
Title
# compose
r

rajesh

08/12/2021, 1:29 PM
Is there any way (or heck) to modify paging (3) data to show ui changes in compose? Like modifying certain object property from paging list when user interact with ui. Paging doesn't seems to support data modification.
a

allan.conda

08/12/2021, 1:32 PM
I just map the PagingData into a UI model, then I keep my own ui state from ViewModel
like having a list of checked items’ ids
r

rajesh

08/12/2021, 1:34 PM
Can you please share some sample code? That would be very useful
Simple GitHub gist would be fine 🙂
s

solidogen

08/12/2021, 3:01 PM
if you use room-based paging source, you can update this item in database. then your paging flow will emit a change
r

rajesh

08/12/2021, 3:01 PM
Hi, I don't want to use room base paging source. I just want to use network response without database caching.
s

solidogen

08/12/2021, 3:03 PM
modyfing items without db is kinda hard - I suggest a simple dao with room fallback to destructive migration, if you don’t care about the tables
r

rajesh

08/12/2021, 3:04 PM
But inserting items in db is time consuming for lots of data, thus creating delay in ui. That's why I want to avoid it
Also, please explain in a bit about this simple dao approach
s

solidogen

08/12/2021, 3:06 PM
I was in your position a while ago, I also tried not to use room, but I’m pretty glad I did. time between clicking update button and seeing viewholder update is like 0.1s I guess
r

rajesh

08/16/2021, 7:10 AM
@solidogen will it work in case I want to always get latest data from network (and save to db only when app is running, once app is restarted, data should be fetched from network) ?
s

solidogen

08/16/2021, 7:11 AM
yes
Copy code
override suspend fun initialize(): InitializeAction {
        // Require that remote REFRESH is launched on initial load and succeeds before launching
        // remote PREPEND / APPEND.
        return InitializeAction.LAUNCH_INITIAL_REFRESH
    }
refresh = refetch all data from network
r

rajesh

08/16/2021, 7:12 AM
Thanks 👍 I'll use it then
2 Views