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:
1 parent
65684b291d
commit
cd589b30a4
2 files changed
+13
-14
No files matched your search
+4
-1
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user