my use case is as follows:-
The user clicks on a list item that triggers a remote api call. on successful completion of this api call my local database will be updated and I am expecting my list item to be updated to reflect the data has indeed been updated.
heres some psuedo code that illustrates how I am implementing this
ViewModel Code
=============
val outcome: Flow<Outcome> = service.myRemoteAPIcall(arg1 , arg2)
val result: Flow<PagingData<MyDataUI>> = myDatabase.fetchLocalData()
Fragment Code
============
viewLifecycleOwner.lifecycleScope.launch {
outcome.take(1).collect { outcome ->
if (outocme == Success)
withContext(Dispatchers.Main) {
result.collect {
myDataAdapter.submitData(it)
}
}
}
}
I do not collect the
PagingData
flow until the remote api call has completed successfully. Therefore I would expect the data that is submitted to my
PagingDataAdapter
to reflect the changes made by the remote api call.
However this is not the case.
i would like to understand two aspects of the observed behaviour.
i). why am i not seeing the updated data? where do I make my mistake.
ii).how can I fix this? how do i "wait" correctly for the remote api to complete before fetching the local (updated) data?