From 9fd8a555f10ffc244b25f36d35e02a8ac11abf92 Mon Sep 17 00:00:00 2001 From: OneWay Date: Thu, 15 Oct 2026 13:34:09 +0800 Subject: [PATCH] fix(settings): keep the update badge after a failed download Errors of downloads this screen did not start no longer touch the status; when the prior status is unknown or still unresolved, today's persisted status is restored or a fresh evaluation runs instead of fabricating UpToDate. --- .../example/research/core/util/NaturalSort.kt | 7 +------ .../research/ui/settings/SettingsViewModel.kt | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/example/research/core/util/NaturalSort.kt b/app/src/main/java/com/example/research/core/util/NaturalSort.kt index 680e226..581ed6c 100644 --- a/app/src/main/java/com/example/research/core/util/NaturalSort.kt +++ b/app/src/main/java/com/example/research/core/util/NaturalSort.kt @@ -118,12 +118,7 @@ private fun compareNatural(a: String, b: String): Int { j = endB } else -> { - if (ca != cb) { - val numeralA = !asciiA && isNumeralChar(ca) - val numeralB = !asciiB && isNumeralChar(cb) - if (numeralA != numeralB) return if (numeralA) -1 else 1 - return ca.compareTo(cb) - } + if (ca != cb) return ca.compareTo(cb) i++ j++ } 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 eccf8f0..df67819 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 @@ -216,14 +216,21 @@ class SettingsViewModel( } } is DownloadState.Error -> { + val startedHere = statusBeforeDownload != DictionaryStatus.Unknown || + isDownloadInProgress isDownloadInProgress = false if (!errorStateHandled) { errorStateHandled = true - dictionaryStatus.value = if (dictionaryState.dictionaries.isEmpty()) { - DictionaryStatus.Empty - } else when (statusBeforeDownload) { - DictionaryStatus.Unknown, DictionaryStatus.Checking -> DictionaryStatus.UpToDate - else -> statusBeforeDownload + if (dictionaryState.dictionaries.isEmpty()) { + dictionaryStatus.value = DictionaryStatus.Empty + } else if (startedHere) { + when (statusBeforeDownload) { + DictionaryStatus.Unknown, DictionaryStatus.Checking -> + viewModelScope.launch { + restoreOrEvaluateDictionaryStatus() + } + else -> dictionaryStatus.value = statusBeforeDownload + } } if (pendingSourceUrls.isNotEmpty()) { pendingSourceUrls.forEach { urlTemplate ->