Refactor(ToolStore): Auto refresh status after install or upgrade tool

This commit is contained in:
2024-08-18 14:46:27 +08:00
parent 21264d8ff7
commit 5839f1d394
2 changed files with 9 additions and 5 deletions

View File

@@ -49,10 +49,10 @@ data class ToolEntity(
val isStar: Boolean = false, val isStar: Boolean = false,
val isInstalled: Boolean = false, var isInstalled: Boolean = false,
@ColumnInfo(defaultValue = "NULL") @ColumnInfo(defaultValue = "NULL")
val upgrade: String? = null var upgrade: String? = null
) { ) {
constructor(toolId: String, authorUsername: String, ver: String, upgrade: String? = null) : constructor(toolId: String, authorUsername: String, ver: String, upgrade: String? = null) :
this( this(

View File

@@ -57,13 +57,17 @@ class ToolStoreViewModel @Inject constructor(
is Result.Success -> { is Result.Success -> {
when (installInfo.value.type) { when (installInfo.value.type) {
ToolStoreUiState.InstallInfo.Type.Install -> toolRepository.saveTool( ToolStoreUiState.InstallInfo.Type.Install -> {
result.data toolRepository.saveTool(
) result.data
)
toolEntity.isInstalled = true
}
ToolStoreUiState.InstallInfo.Type.Upgrade -> { ToolStoreUiState.InstallInfo.Type.Upgrade -> {
toolRepository.removeTool(toolEntity) toolRepository.removeTool(toolEntity)
toolRepository.saveTool(result.data) toolRepository.saveTool(result.data)
toolEntity.upgrade = null
} }
} }