diff --git a/app/src/main/java/com/example/research/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/example/research/ui/settings/SettingsViewModel.kt index 7c20dad..33e60e2 100644 --- a/app/src/main/java/com/example/research/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/example/research/ui/settings/SettingsViewModel.kt @@ -524,6 +524,25 @@ class SettingsViewModel( ): List = DictionarySourceFileMatcher.installedSources(sources, dictionaries) + private suspend fun installedDictionariesAreCurrent(): Boolean { + val sources = preferencesManager.dictionarySources.first() + val dictionaries = localDictionaryRepository.dictionaries.first() + val datedEnabledSources = installedEnabledSources(sources, dictionaries) + .filter { DictionarySource.hasDatePlaceholder(it.urlTemplate) } + if (datedEnabledSources.isEmpty()) return true + val fileNames = localDictionaryRepository.listDictionaryPayloadFileNames( + preferencesManager.dictionaryPath + ) ?: return true + val today = DateUtils.getCurrentDateString() + return datedEnabledSources.all { source -> + val baseName = DictionarySource.extractFileName(source.urlTemplate, today) + .removeSuffix(".gz") + .removeSuffix(".dsl") + .removeSuffix(".dz") + fileNames.any { it.startsWith(baseName) } + } + } + private fun cancelDownload() { // Cancel the ViewModel-side scan job so no further status recomputes localDictionaryRepository.cancelIndexing() @@ -584,7 +603,10 @@ class SettingsViewModel( "NeedsUpdate" -> DictionaryStatus.NeedsUpdate else -> null } - if (restoredStatus != null && savedStatusDate == DateUtils.getCurrentDateString()) { + if (restoredStatus != null && + savedStatusDate == DateUtils.getCurrentDateString() && + withContext(Dispatchers.IO) { installedDictionariesAreCurrent() } + ) { dictionaryStatus.value = restoredStatus } else { dictionaryStatus.value = DictionaryStatus.Checking