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