0

Hey there i have a bottom navigation view and multiple fragments to be exact 3 of them what they do->

  1. Home -> Shows random images from a paginated api with a heart icon based on if its saved
  2. Search -> Searches for images with a query from a paginated api with a heart icon based on if its saved
  3. Saved-> Shows Saved images with an active heart icon

My issue is that when i get data from a paginated api i compare it to the data in paging resource and it works fine but When i save a image and go to saved fragment and unsave it on the home it still shows saved which is right based on logic but i can't find any other way to solve this other than giving a database access to adapter but that is again against mvvm

i am using a room database paging 3 library and mvvm architecture pattern

Aditya Bhawsar
  • 156
  • 1
  • 2
  • 8
  • Are both adapters driven by PagingSources provided by Room? Make sure both are driven by the same table and that you're writing the state into db. Room should propagate invalidation for you which will cause both to pick up changes once they resume loading. – dlam Nov 29 '20 at 18:41
  • no paging data is given be the REST api and i want to keep checking that with my room database and also get any changes in the room database – Aditya Bhawsar Nov 29 '20 at 19:00
  • The recommended approach would be to make your network calls via RemoteMediator and use the PagingSource impl provided by Room (simply set the return type of a query in your dao). Paging handles updates to the backing dataset via invalidation and Room will propagate the invalidation signal for you. RemoteMediator provides callbacks that allows you to make the network calls and write to db with room. – dlam Nov 30 '20 at 10:40

0 Answers0