diff --git a/engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt b/engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt index 7e3a94bb76..d81271b276 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt @@ -67,11 +67,11 @@ abstract class FhirSyncWorker(appContext: Context, workerParams: WorkerParameter val synchronizer = FhirSynchronizer( - applicationContext, getFhirEngine(), Uploader(dataSource), DownloaderImpl(dataSource, getDownloadWorkManager()), getConflictResolver(), + FhirEngineProvider.getFhirDataStore(applicationContext), ) val job = @@ -101,7 +101,7 @@ abstract class FhirSyncWorker(appContext: Context, workerParams: WorkerParameter // await/join is needed to collect states completely kotlin.runCatching { job.join() }.onFailure(Timber::w) - // setProgress(output) + setProgress(output) Timber.d("Received result from worker $result and sending output $output") diff --git a/engine/src/main/java/com/google/android/fhir/sync/FhirSynchronizer.kt b/engine/src/main/java/com/google/android/fhir/sync/FhirSynchronizer.kt index 10f4652c1c..da3447037f 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/FhirSynchronizer.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/FhirSynchronizer.kt @@ -16,9 +16,7 @@ package com.google.android.fhir.sync -import android.content.Context import com.google.android.fhir.FhirEngine -import com.google.android.fhir.FhirEngineProvider import com.google.android.fhir.sync.download.DownloadState import com.google.android.fhir.sync.download.Downloader import com.google.android.fhir.sync.upload.LocalChangesFetchMode @@ -46,18 +44,16 @@ data class ResourceSyncException(val resourceType: ResourceType, val exception: /** Class that helps synchronize the data source and save it in the local database */ internal class FhirSynchronizer( - context: Context, private val fhirEngine: FhirEngine, private val uploader: Uploader, private val downloader: Downloader, private val conflictResolver: ConflictResolver, + private val datastoreUtil: FhirDataStore, ) { private val _syncState = MutableSharedFlow() val syncState: SharedFlow = _syncState - private val datastoreUtil = FhirEngineProvider.getFhirDataStore(context) - private suspend fun setSyncState(state: SyncJobStatus) = _syncState.emit(state) private suspend fun setSyncState(result: SyncResult): SyncJobStatus { diff --git a/engine/src/test/java/com/google/android/fhir/sync/FhirSynchronizerTest.kt b/engine/src/test/java/com/google/android/fhir/sync/FhirSynchronizerTest.kt index ebfb432d46..4c850eb831 100644 --- a/engine/src/test/java/com/google/android/fhir/sync/FhirSynchronizerTest.kt +++ b/engine/src/test/java/com/google/android/fhir/sync/FhirSynchronizerTest.kt @@ -16,7 +16,6 @@ package com.google.android.fhir.sync -import androidx.test.core.app.ApplicationProvider import com.google.android.fhir.LocalChangeToken import com.google.android.fhir.sync.download.DownloadState import com.google.android.fhir.sync.download.Downloader @@ -49,6 +48,8 @@ class FhirSynchronizerTest { @Mock private lateinit var conflictResolver: ConflictResolver + @Mock private lateinit var fhirDataStore: FhirDataStore + private lateinit var fhirSynchronizer: FhirSynchronizer @Before @@ -56,11 +57,11 @@ class FhirSynchronizerTest { MockitoAnnotations.openMocks(this) fhirSynchronizer = FhirSynchronizer( - ApplicationProvider.getApplicationContext(), TestFhirEngineImpl, uploader, downloader, conflictResolver, + fhirDataStore, ) }