android / architecture-samples

A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.
Apache License 2.0
44.3k stars 11.62k forks source link

Simplify the network data source #915

Closed dturner closed 1 year ago

dturner commented 1 year ago

tl;dr the local data source is now the source of truth, the network data source has only 2 methods which load and save all data.

One of the goals of this sample is to demonstrate how to deal with different data sources but the NetworkDataSource interface was very similar to the local TasksDao interface.

For this reason, I have simplified the NetworkDataSource interface to just 2 methods loadTasks and saveTasks, which load and save all tasks respectively.

I've also changed the way that data synchronisation works inside DefaultTasksRepository:

This is not a robust sync implementation. In a production app, if the remote write failed and a force refresh was performed the local data would be overwritten. But I think it's better than what we had before which was essentially random behaviour.