Skip to content

Commit

Permalink
perf: github upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jan 24, 2025
1 parent 281332e commit be24cc3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
53 changes: 32 additions & 21 deletions app/src/main/kotlin/li/songe/gkd/ui/component/UploadOptions.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package li.songe.gkd.ui.component

import androidx.compose.animation.AnimatedContent
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ClipboardUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
Expand All @@ -16,6 +16,7 @@ import li.songe.gkd.MainViewModel
import li.songe.gkd.data.GithubPoliciesAsset
import li.songe.gkd.util.GithubCookieException
import li.songe.gkd.util.LoadStatus
import li.songe.gkd.util.copyText
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.privacyStoreFlow
import li.songe.gkd.util.toast
Expand Down Expand Up @@ -70,7 +71,7 @@ class UploadOptions(

private fun stopTask() {
if (statusFlow.value is LoadStatus.Loading && job != null) {
job?.cancel("您取消了上传")
job?.cancel("上传已取消")
job = null
}
}
Expand All @@ -84,9 +85,16 @@ class UploadOptions(
AlertDialog(
title = { Text(text = "上传文件中") },
text = {
LinearProgressIndicator(
progress = { status.progress },
)
val showExactProgress = 0f < status.progress && status.progress < 1f
AnimatedContent(showExactProgress) { showExact ->
if (showExact) {
LinearProgressIndicator(
progress = { status.progress },
)
} else {
LinearProgressIndicator()
}
}
},
onDismissRequest = { },
confirmButton = {
Expand All @@ -101,23 +109,26 @@ class UploadOptions(

is LoadStatus.Success -> {
val href = showHref(status.result)
AlertDialog(title = { Text(text = "上传完成") }, text = {
Text(text = href)
}, onDismissRequest = {}, dismissButton = {
TextButton(onClick = {
statusFlow.value = null
}) {
Text(text = "关闭")
}
}, confirmButton = {
TextButton(onClick = {
ClipboardUtils.copyText(href)
toast("复制成功")
statusFlow.value = null
}) {
Text(text = "复制并关闭")
AlertDialog(
title = { Text(text = "上传完成") },
text = { Text(text = href) },
onDismissRequest = {},
dismissButton = {
TextButton(onClick = {
statusFlow.value = null
}) {
Text(text = "关闭")
}
},
confirmButton = {
TextButton(onClick = {
copyText(href)
statusFlow.value = null
}) {
Text(text = "复制并关闭")
}
}
})
)
}

is LoadStatus.Failure -> {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/kotlin/li/songe/gkd/util/Github.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ fun EditGithubCookieDlg(showEditCookieDlgFlow: MutableStateFlow<Boolean>) {
TextButton(onClick = {
showEditCookieDlgFlow.value = false
privacyStoreFlow.update { it.copy(githubCookie = value.trim()) }
toast("更新成功")
}) {
Text(text = "确认")
}
Expand Down

0 comments on commit be24cc3

Please sign in to comment.