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.
This commit is contained in:
OneWay committed 2026-09-27 11:00:00 +08:00
1 parent 65684b291d
commit 5c275e16d6
2 files changed
+8 -14

No files matched your search

@@ -7,6 +7,7 @@ import com.example.research.common.util.FileStorageManager
import com.example.research.common.util.DocumentFileInfo import com.example.research.common.util.DocumentFileInfo
import com.example.research.core.domain.model.DictionarySource import com.example.research.core.domain.model.DictionarySource
import com.example.research.feature.download.config.DictionaryConfig import com.example.research.feature.download.config.DictionaryConfig
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
@@ -101,9 +102,11 @@ class DictionaryChecker(
} }
return@withContext !serverCanOfferNewer return@withContext !serverCanOfferNewer
} catch (e: CancellationException) {
throw e
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Error checking currency: ${e.message}", e) Log.e(TAG, "Error checking currency: ${e.message}", e)
false true
} }
} }
@@ -133,8 +133,6 @@ class SettingsViewModel(
private fun setupStateObservation() { private fun setupStateObservation() {
viewModelScope.launch { viewModelScope.launch {
var wasIndexing = false
val dictionaryStateInputs = combine( val dictionaryStateInputs = combine(
preferencesManager.themeMode.map { mode -> preferencesManager.themeMode.map { mode ->
try { AppTheme.valueOf(mode) } catch (_: Exception) { AppTheme.SYSTEM } try { AppTheme.valueOf(mode) } catch (_: Exception) { AppTheme.SYSTEM }
@@ -174,18 +172,7 @@ class SettingsViewModel(
} }
combine(dictionaryStateInputs, operationStateInputs) { dictionaryState, operationState -> combine(dictionaryStateInputs, operationStateInputs) { dictionaryState, operationState ->
// Handle indexing completion side effect
val isIndexing = dictionaryState.indexingProgress.isIndexing val isIndexing = dictionaryState.indexingProgress.isIndexing
if (wasIndexing && !isIndexing) {
if (isDownloadInProgress) {
isDownloadInProgress = false
dictionaryStatus.value = withContext(Dispatchers.IO) {
evaluateDictionaryStatus()
}
}
}
wasIndexing = isIndexing
when (operationState.downloadState) { when (operationState.downloadState) {
is DownloadState.Loading, is DownloadState.Extracting -> { is DownloadState.Loading, is DownloadState.Extracting -> {
isDownloadInProgress = true isDownloadInProgress = true
@@ -194,6 +181,10 @@ class SettingsViewModel(
} }
is DownloadState.Success -> { is DownloadState.Success -> {
pendingSourceUrls.clear() pendingSourceUrls.clear()
isDownloadInProgress = false
dictionaryStatus.value = withContext(Dispatchers.IO) {
evaluateDictionaryStatus()
}
} }
is DownloadState.Error -> { is DownloadState.Error -> {
isDownloadInProgress = false isDownloadInProgress = false