Added a coroutine scope to DefaultTaskRepository so that it can launch the job which writes local to network data asynchronously. This fixes an issue in the current app where when creating or updating any task, the UI would pause for 2 seconds waiting for the network data source (which has a simulated 2 second network latency).
For the main app, an application scope is used. This is defined using the ApplicationScope qualifier.
For tests, TestScope is used.
Refactored the hilt configuration to use @Binds rather than @Provides methods. This (in my mind anyway) makes things simpler to understand - @Provides should be reserved for objects which there is no other way to create (such as those from Room).
Updated DefaultTaskRepositoryTest to use StandardTestDispatcher rather than a hardcoded Dispatchers.Main when creating the DefaultTaskRepository
Renamed DefaultTaskRepository's parameters for the data sources to make it more obvious what they are.
What have I done and why?
DefaultTaskRepository
so that it can launch the job which writes local to network data asynchronously. This fixes an issue in the current app where when creating or updating any task, the UI would pause for 2 seconds waiting for the network data source (which has a simulated 2 second network latency).For the main app, an application scope is used. This is defined using the
ApplicationScope
qualifier. For tests,TestScope
is used.Refactored the hilt configuration to use
@Binds
rather than@Provides
methods. This (in my mind anyway) makes things simpler to understand -@Provides
should be reserved for objects which there is no other way to create (such as those from Room).Updated
DefaultTaskRepositoryTest
to useStandardTestDispatcher
rather than a hardcodedDispatchers.Main
when creating theDefaultTaskRepository
Renamed
DefaultTaskRepository
's parameters for the data sources to make it more obvious what they are.Note: This change also includes https://github.com/android/architecture-samples/pull/928