From 6fa7a2e9e09be4bd1c4da02f41c60bb2d7bce002 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Mon, 2 Oct 2023 17:14:44 -0600 Subject: [PATCH] trigger the dirty favorite tools sync when the user adds/removes a favorite --- .../org/cru/godtools/ui/tools/ToolViewModels.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolViewModels.kt b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolViewModels.kt index 7c17108e32..f2049c1d3f 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolViewModels.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolViewModels.kt @@ -30,6 +30,7 @@ import org.cru.godtools.downloadmanager.GodToolsDownloadManager import org.cru.godtools.model.Language import org.cru.godtools.model.Tool import org.cru.godtools.model.Translation +import org.cru.godtools.sync.GodToolsSyncService internal const val EXTRA_ADDITIONAL_LANGUAGE = "additionalLanguage" @@ -42,6 +43,7 @@ class ToolViewModels @Inject constructor( private val languagesRepository: LanguagesRepository, private val manifestManager: ManifestManager, private val settings: Settings, + private val syncService: GodToolsSyncService, private val toolsRepository: ToolsRepository, private val translationsRepository: TranslationsRepository, savedState: SavedStateHandle, @@ -123,10 +125,16 @@ class ToolViewModels @Inject constructor( .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) fun pinTool() { - viewModelScope.launch { toolsRepository.pinTool(code) } + viewModelScope.launch { + toolsRepository.pinTool(code) + syncService.syncDirtyFavoriteTools() + } settings.setFeatureDiscovered(Settings.FEATURE_TOOL_FAVORITE) } - fun unpinTool() = viewModelScope.launch { toolsRepository.unpinTool(code) } + fun unpinTool() = viewModelScope.launch { + toolsRepository.unpinTool(code) + syncService.syncDirtyFavoriteTools() + } } private fun Flow.attachmentFileFlow(transform: (value: Tool?) -> Long?) = this