Более аккуратная обработка сетвой ошибки на экране Vault

This commit is contained in:
2026-05-22 13:33:14 +03:00
parent 6ab402da51
commit 96e9de49c3
2 changed files with 17 additions and 9 deletions

View File

@@ -115,22 +115,24 @@ class EncryptedStorageAccessor(
launch {
source.numberOfFiles.collect {
if(it == null)
if (it == null) {
_numberOfFiles.value = null
else
{
_numberOfFiles.value = it - getSystemFiles().size
} else {
val hiddenCount = runCatching { getSystemFiles().size }.getOrNull() ?: return@collect
_numberOfFiles.value = it - hiddenCount
}
}
}
launch {
source.size.collect { sourceSize ->
if(sourceSize == null)
if (sourceSize == null) {
_size.value = null
else
{
_size.value = sourceSize - getSystemFiles().sumOf { it.metaInfo.size }
} else {
val hiddenBytes = runCatching {
getSystemFiles().sumOf { file -> file.metaInfo.size }
}.getOrNull() ?: return@collect
_size.value = sourceSize - hiddenBytes
}
}
}

View File

@@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
import com.github.nullptroma.wallenc.domain.datatypes.StorageMetaLoadState
import com.github.nullptroma.wallenc.domain.datatypes.Tree
import com.github.nullptroma.wallenc.domain.errors.WallencException
import com.github.nullptroma.wallenc.domain.errors.toWallencException
import com.github.nullptroma.wallenc.domain.interfaces.ILogger
import com.github.nullptroma.wallenc.domain.interfaces.IStorage
@@ -188,9 +189,14 @@ abstract class AbstractVaultBrowserViewModel(
ctx.log(TaskLogLevel.Info, uiStrings(R.string.task_log_rescanning_vault_storages))
manageVaultUseCase.rescanStorages(vaultUuid)
ctx.log(TaskLogLevel.Info, uiStrings(R.string.task_log_rescan_vault_storages_done))
val vault = manageVaultUseCase.find(vaultUuid)
if (vault != null && !vault.isAvailable.value) {
emitTaskError(WallencException.Network.IoFailed())
}
} catch (e: Exception) {
logger.debug(TAG, "rescanStorages failed: ${e.stackTraceToString()}")
ctx.log(TaskLogLevel.Error, uiStrings(R.string.task_log_rescan_vault_storages_failed))
emitTaskError(e)
}
},
)
@@ -224,7 +230,7 @@ abstract class AbstractVaultBrowserViewModel(
} catch (e: Exception) {
logger.debug(TAG, "createStorage failed: ${e.stackTraceToString()}")
ctx.log(TaskLogLevel.Error, uiStrings(R.string.task_log_add_vault_failed))
throw e
emitTaskError(e)
}
},
)