Skip to content

Commit

Permalink
perf: 优化创建文件夹逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Nov 18, 2023
1 parent b4f5f85 commit c91fd2c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/li/songe/gkd/ui/HomePageVm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import li.songe.gkd.util.LoadStatus
import li.songe.gkd.util.checkUpdate
import li.songe.gkd.util.client
import li.songe.gkd.util.dbFolder
import li.songe.gkd.util.initFolder
import li.songe.gkd.util.json
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.storeFlow
Expand Down Expand Up @@ -86,6 +87,12 @@ class HomePageVm @Inject constructor() : ViewModel() {
}
}
}

viewModelScope.launchTry(Dispatchers.IO) {
// 在某些机型由于未知原因创建失败
// 在此保证每次重新打开APP都能重新检测创建
initFolder()
}
}

val uploadStatusFlow = MutableStateFlow<LoadStatus<GithubPoliciesAsset>?>(null)
Expand All @@ -105,10 +112,10 @@ class HomePageVm @Inject constructor() : ViewModel() {
onUpload { bytesSentTotal, contentLength ->
if (uploadStatusFlow.value is LoadStatus.Loading) {
uploadStatusFlow.value =
LoadStatus.Loading(bytesSentTotal / contentLength.toFloat())
LoadStatus.Loading(bytesSentTotal / contentLength.toFloat())
}
}
}
}
if (response.headers["X_RPC_OK"] == "true") {
val policiesAsset = response.body<GithubPoliciesAsset>()
uploadStatusFlow.value = LoadStatus.Success(policiesAsset)
Expand Down

0 comments on commit c91fd2c

Please sign in to comment.