优化进度显示

This commit is contained in:
1
2024-09-02 11:09:32 +08:00
parent e739977b89
commit c9c9d7e4f9
5 changed files with 55 additions and 55 deletions

View File

@@ -14,8 +14,8 @@ android {
applicationId = "com.donut.mixfile"
minSdk = 24
targetSdk = 34
versionCode = 5
versionName = "1.0.4"
versionCode = 6
versionName = "1.0.4.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {

View File

@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1" name="viewport"/>
<title>MixFile</title>
<script type="module" crossorigin src="/assets/index-BDpeJXT8.js"></script>
<script type="module" crossorigin src="/assets/index-BbG3rMIQ.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BuZ9x1Ok.css">
</head>
<body>

View File

@@ -55,9 +55,15 @@ fun readClipBoardText(): String {
}
fun formatFileSize(bytes: Long): String {
fun formatFileSize(bytes: Long, mb: Boolean = false): String {
if (bytes <= 0) return "0 B"
if (mb) {
return String.format(
Locale.US,
"%.2f MB",
bytes / 1024.0 / 1024.0
)
}
val units = arrayOf("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
val digitGroups = (log10(bytes.toDouble()) / log10(1024.0)).toInt()

View File

@@ -19,6 +19,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.unit.dp
import com.donut.mixfile.util.formatFileSize
import okhttp3.Interceptor
import okhttp3.MediaType
import okhttp3.Response
@@ -32,19 +33,6 @@ import java.util.Locale
import kotlin.math.log10
import kotlin.math.pow
fun formatFileSize(bytes: Long): String {
if (bytes <= 0) return "0 B"
val units = arrayOf("B", "KB", "MB", "GB", "TB")
val digitGroups = (log10(bytes.toDouble()) / log10(1024.0)).toInt()
return String.format(
Locale.US,
"%.1f %s",
bytes / 1024.0.pow(digitGroups.toDouble()),
units[digitGroups]
)
}
class ProgressInterceptor(private val progressListener: ProgressListener) : Interceptor {
@@ -178,7 +166,13 @@ fun LoadingBar(
progress = { progress },
modifier = Modifier.fillMaxWidth(),
)
Text(text = "${tip}: ${formatFileSize(bytesWritten)}/${formatFileSize(contentLength)}")
Text(
text = "${tip}: ${formatFileSize(bytesWritten, true)}/${
formatFileSize(
contentLength
)
}"
)
}
}
}