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:
When reading tasks they are obtained locally, unless forceRefresh is specified, in which case they are first obtained from the network data source
When writing information they are written locally first, then written to the network data source
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.
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 localTasksDao
interface.For this reason, I have simplified the
NetworkDataSource
interface to just 2 methodsloadTasks
andsaveTasks
, which load and save all tasks respectively.I've also changed the way that data synchronisation works inside
DefaultTasksRepository
:forceRefresh
is specified, in which case they are first obtained from the network data sourceThis 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.