diff --git a/app/src/main/java/com/example/research/feature/download/repository/DictionaryChecker.kt b/app/src/main/java/com/example/research/feature/download/repository/DictionaryChecker.kt index cf1b131..020ff20 100644 --- a/app/src/main/java/com/example/research/feature/download/repository/DictionaryChecker.kt +++ b/app/src/main/java/com/example/research/feature/download/repository/DictionaryChecker.kt @@ -64,7 +64,14 @@ class DictionaryChecker( val previousDate = DateUtils.getPreviousDateString() val dictFiles = getDictFiles(folderUri, files) - val allHaveToday = enabledSources.all { source -> + val datedSources = enabledSources.filter { source -> + DictionarySource.hasDatePlaceholder(source.urlTemplate) + } + if (datedSources.isEmpty()) { + return@withContext true + } + + val allHaveToday = datedSources.all { source -> dictFiles.hasFileForSource(source, currentDate) } @@ -72,19 +79,28 @@ class DictionaryChecker( return@withContext true } - val allHaveYesterday = enabledSources.all { source -> + val allHaveYesterday = datedSources.all { source -> dictFiles.hasFileForSource(source, previousDate) } if (allHaveYesterday) { - val serverHasToday = enabledSources.any { source -> + val serverHasToday = datedSources.any { source -> isSourceAvailableOnServer(source, currentDate) } return@withContext !serverHasToday } - false + val serverCanOfferNewer = datedSources.any { source -> + when (probeSource(source, currentDate)) { + SourceAvailability.AVAILABLE -> true + SourceAvailability.NOT_FOUND -> + probeSource(source, previousDate) == SourceAvailability.AVAILABLE + SourceAvailability.UNKNOWN -> false + } + } + + return@withContext !serverCanOfferNewer } catch (e: Exception) { Log.e(TAG, "Error checking currency: ${e.message}", e) false