From 491f71ff41a5f40101fe7d8ed88bc3481f9f39e1 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Mon, 2 Oct 2023 08:53:38 -0600 Subject: [PATCH] trigger the favorite tools sync from the dashboard --- .../org/cru/godtools/ui/dashboard/DashboardViewModel.kt | 6 +++++- .../kotlin/org/cru/godtools/ExternalSingletonsModule.kt | 1 + .../org/cru/godtools/ui/dashboard/DashboardViewModelTest.kt | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardViewModel.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardViewModel.kt index ababc19a7e..478e9cf8dc 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardViewModel.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.map @@ -53,7 +54,10 @@ class DashboardViewModel @Inject constructor( @Suppress("DeferredResultUnused") syncService.syncToolSharesAsync() syncsRunning.value++ - syncService.syncTools(force) + coroutineScope { + launch { syncService.syncFavoriteTools(force) } + launch { syncService.syncTools(force) } + } syncsRunning.value-- } } diff --git a/app/src/test/kotlin/org/cru/godtools/ExternalSingletonsModule.kt b/app/src/test/kotlin/org/cru/godtools/ExternalSingletonsModule.kt index 6315514824..12d61745ae 100644 --- a/app/src/test/kotlin/org/cru/godtools/ExternalSingletonsModule.kt +++ b/app/src/test/kotlin/org/cru/godtools/ExternalSingletonsModule.kt @@ -66,6 +66,7 @@ class ExternalSingletonsModule { val syncService: GodToolsSyncService by lazy { mockk { coEvery { syncTools(any()) } returns true + coEvery { syncFavoriteTools(any()) } returns true every { syncFollowupsAsync() } returns CompletableDeferred(true) every { syncToolSharesAsync() } returns CompletableDeferred(true) } diff --git a/app/src/test/kotlin/org/cru/godtools/ui/dashboard/DashboardViewModelTest.kt b/app/src/test/kotlin/org/cru/godtools/ui/dashboard/DashboardViewModelTest.kt index 1a8d11180d..f20e3635da 100644 --- a/app/src/test/kotlin/org/cru/godtools/ui/dashboard/DashboardViewModelTest.kt +++ b/app/src/test/kotlin/org/cru/godtools/ui/dashboard/DashboardViewModelTest.kt @@ -33,6 +33,7 @@ class DashboardViewModelTest { every { syncFollowupsAsync() } returns CompletableDeferred() every { syncToolSharesAsync() } returns CompletableDeferred() coEvery { syncTools(any()) } returns true + coEvery { syncFavoriteTools(any()) } returns true } private val testScope = TestScope() @@ -59,6 +60,7 @@ class DashboardViewModelTest { syncService.syncFollowupsAsync() syncService.syncToolSharesAsync() syncService.syncTools(false) + syncService.syncFavoriteTools(false) } } @@ -90,7 +92,8 @@ class DashboardViewModelTest { coVerifyAll { syncService.syncFollowupsAsync() syncService.syncToolSharesAsync() - syncService.syncTools(any()) + syncService.syncTools(false) + syncService.syncFavoriteTools(false) } } }