From cd589b30a4dae8760dc4fb3c6a442068c9fda5c5 Mon Sep 17 00:00:00 2001 From: OneWay Date: Sun, 27 Sep 2026 11:00:00 +0800 Subject: [PATCH] fix(download): don't show the update card for current dictionaries areDictionariesUpToDate() mapped every exception to NeedsUpdate, and the post-update recheck ran after the first indexed source of a batch, before later sources finished downloading; the interim NeedsUpdate persisted for the day. Treat unexpected errors as up to date, rethrow cancellation, and recheck once when the download batch completes. --- .../download/repository/DictionaryChecker.kt | 5 ++++- .../research/ui/settings/SettingsViewModel.kt | 22 ++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) 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 020ff20..80a2718 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 @@ -7,6 +7,7 @@ import com.example.research.common.util.FileStorageManager import com.example.research.common.util.DocumentFileInfo import com.example.research.core.domain.model.DictionarySource import com.example.research.feature.download.config.DictionaryConfig +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import okhttp3.OkHttpClient @@ -101,9 +102,11 @@ class DictionaryChecker( } return@withContext !serverCanOfferNewer + } catch (e: CancellationException) { + throw e } catch (e: Exception) { Log.e(TAG, "Error checking currency: ${e.message}", e) - false + true } } 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 9c5f8e8..7c20dad 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 @@ -96,6 +96,7 @@ class SettingsViewModel( private var cancelRefreshPending = false private var errorStateHandled = false + private var successStateHandled = false private var statusBeforeDownload: DictionaryStatus = DictionaryStatus.Unknown init { @@ -133,8 +134,6 @@ class SettingsViewModel( private fun setupStateObservation() { viewModelScope.launch { - var wasIndexing = false - val dictionaryStateInputs = combine( preferencesManager.themeMode.map { mode -> try { AppTheme.valueOf(mode) } catch (_: Exception) { AppTheme.SYSTEM } @@ -174,26 +173,23 @@ class SettingsViewModel( } combine(dictionaryStateInputs, operationStateInputs) { dictionaryState, operationState -> - // Handle indexing completion side effect val isIndexing = dictionaryState.indexingProgress.isIndexing - if (wasIndexing && !isIndexing) { - if (isDownloadInProgress) { - isDownloadInProgress = false - dictionaryStatus.value = withContext(Dispatchers.IO) { - evaluateDictionaryStatus() - } - } - } - wasIndexing = isIndexing - when (operationState.downloadState) { is DownloadState.Loading, is DownloadState.Extracting -> { isDownloadInProgress = true cancelRefreshPending = false errorStateHandled = false + successStateHandled = false } is DownloadState.Success -> { pendingSourceUrls.clear() + isDownloadInProgress = false + if (!successStateHandled) { + successStateHandled = true + dictionaryStatus.value = withContext(Dispatchers.IO) { + evaluateDictionaryStatus() + } + } } is DownloadState.Error -> { isDownloadInProgress = false