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.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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private var cancelRefreshPending = false
|
private var cancelRefreshPending = false
|
||||||
private var errorStateHandled = false
|
private var errorStateHandled = false
|
||||||
|
private var successStateHandled = false
|
||||||
private var statusBeforeDownload: DictionaryStatus = DictionaryStatus.Unknown
|
private var statusBeforeDownload: DictionaryStatus = DictionaryStatus.Unknown
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -133,8 +134,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,26 +173,23 @@ 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
|
||||||
cancelRefreshPending = false
|
cancelRefreshPending = false
|
||||||
errorStateHandled = false
|
errorStateHandled = false
|
||||||
|
successStateHandled = false
|
||||||
}
|
}
|
||||||
is DownloadState.Success -> {
|
is DownloadState.Success -> {
|
||||||
pendingSourceUrls.clear()
|
pendingSourceUrls.clear()
|
||||||
|
isDownloadInProgress = false
|
||||||
|
if (!successStateHandled) {
|
||||||
|
successStateHandled = true
|
||||||
|
dictionaryStatus.value = withContext(Dispatchers.IO) {
|
||||||
|
evaluateDictionaryStatus()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is DownloadState.Error -> {
|
is DownloadState.Error -> {
|
||||||
isDownloadInProgress = false
|
isDownloadInProgress = false
|
||||||
|
|||||||
Reference in new issue
Block a user