Recently I checked the nowinandroid project to fol...
# compose
r
Recently I checked the nowinandroid project to follow the best practices, but its repoistry layer doesn't seem to have any content about network requests. Both room/datastore support Kotlin Flow, and it will be automatically updated in Flow after data manipulation. But what about okhttp/retrofit? If the user action is handled in the viewmodel, how can I inform the api layer to re-initiate the network request and return the new data in the flow? are there any examples
y
Isn't this example covering that case? https://github.com/android/nowinandroid/blob/ef42543b32b58038fbe5cdcee17af8fe69756[…]inandroid/core/data/repository/OfflineFirstAuthorsRepository.kt The syncWith does network calls via retrofit, that publish to the DB and presumably trigger updates to the Room query flows.
r
I'm referring to pure network requests, no database (ROOM) involved. For example, app get a total number of likes from the backend, and then the user clicks likes, then tha app should send a new request for like and the latest likes count is refetched from the backend. What should be done in Repo? MutableStateFlow?
I'm not proficient with flow so I don't know what is the best practice
f
you should make both functions just suspend function and not wrap it in flow as it is not needed for your case. As for the value you should observe it in a state object that you can update. Then when the user performs an action you can call the like and getLikes usecases and update your state objects. Your observing UI should then be updated automatically