diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt index c578f37da9..85b6059587 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt @@ -1067,7 +1067,7 @@ constructor( // TODO This will require a new config model for related entity location filter val locationIds = syncLocationIds - .map { retrieveSubLocations(it).map { subLocation -> subLocation.logicalId } } + .map { retrieveFlattenedSubLocations(it).map { subLocation -> subLocation.logicalId } } .flatten() .plus(syncLocationIds) diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt index 99481b307a..dcbb8c50bc 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainActivity.kt @@ -161,10 +161,10 @@ open class AppMainActivity : BaseMultiLanguageActivity(), QuestionnaireHandler, applicationConfiguration.usePractitionerAssignedLocationOnSync || runBlocking { syncLocationIdsProtoStore.data.firstOrNull() }?.isNotEmpty() == true ) { - triggerSync() + schedulePeriodicSync() } } else { - triggerSync() + schedulePeriodicSync() } } else { showToast( diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt index 1a64de42bc..53b7e7cccc 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/AppMainViewModel.kt @@ -310,7 +310,7 @@ constructor( } } - fun triggerSync() { + fun schedulePeriodicSync() { viewModelScope.launch { syncBroadcaster.schedulePeriodicSync(applicationConfiguration.syncInterval) } diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/multiselect/MultiSelectBottomSheetFragment.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/multiselect/MultiSelectBottomSheetFragment.kt index 71fcdf6221..8538bc6561 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/multiselect/MultiSelectBottomSheetFragment.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/multiselect/MultiSelectBottomSheetFragment.kt @@ -26,6 +26,7 @@ import androidx.compose.ui.platform.ComposeView import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.viewModelScope import androidx.navigation.fragment.navArgs import com.google.android.material.bottomsheet.BottomSheetDialogFragment import dagger.hilt.android.AndroidEntryPoint @@ -59,7 +60,8 @@ class MultiSelectBottomSheetFragment() : BottomSheetDialogFragment() { multiSelectViewModel.saveSelectedLocations(requireContext()) appMainViewModel.run { if (requireContext().isDeviceOnline()) { - triggerSync() + viewModelScope.launch { syncBroadcaster.runOneTimeSync() } + schedulePeriodicSync() } else { requireContext() .showToast(