From f5ed806d8be6bdfa9f92cc54d3a6efd11292a4ab Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Sat, 29 Mar 2025 20:34:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=84=E4=BB=B6=E5=8C=96?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 2 +- .../todo/ui/components/ProgressIndicator.kt | 39 +++++++++++++++++++ .../todo/ui/pages/main/ProgressFragment.kt | 15 ++----- 3 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 app/src/main/kotlin/cn/super12138/todo/ui/components/ProgressIndicator.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4d36a47..21af52c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -34,7 +34,7 @@ android { applicationId = "cn.super12138.todo" minSdk = 24 targetSdk = 36 - versionCode = 617 + versionCode = 618 versionName = "2.1.2" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/components/ProgressIndicator.kt b/app/src/main/kotlin/cn/super12138/todo/ui/components/ProgressIndicator.kt new file mode 100644 index 0000000..de34004 --- /dev/null +++ b/app/src/main/kotlin/cn/super12138/todo/ui/components/ProgressIndicator.kt @@ -0,0 +1,39 @@ +package cn.super12138.todo.ui.components + +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.ProgressIndicatorDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.StrokeCap +import androidx.compose.ui.unit.Dp + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun AnimatedCircularProgressIndicator( + progress: Float, + modifier: Modifier = Modifier, + color: Color = ProgressIndicatorDefaults.circularColor, + strokeWidth: Dp = ProgressIndicatorDefaults.CircularStrokeWidth, + trackColor: Color = ProgressIndicatorDefaults.circularDeterminateTrackColor, + strokeCap: StrokeCap = ProgressIndicatorDefaults.CircularDeterminateStrokeCap, + gapSize: Dp = ProgressIndicatorDefaults.CircularIndicatorTrackGapSize +) { + val animatedProgress by animateFloatAsState( + targetValue = progress, + animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec + ) + + CircularProgressIndicator( + progress = { animatedProgress }, + modifier = modifier, + color = color, + strokeWidth = strokeWidth, + trackColor = trackColor, + strokeCap = strokeCap, + gapSize = gapSize + ) +} \ No newline at end of file diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ProgressFragment.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ProgressFragment.kt index 1553e17..80bd87c 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ProgressFragment.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ProgressFragment.kt @@ -1,23 +1,20 @@ package cn.super12138.todo.ui.pages.main import androidx.compose.animation.AnimatedVisibility -import androidx.compose.animation.core.animateFloatAsState import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.size -import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.ProgressIndicatorDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import cn.super12138.todo.R +import cn.super12138.todo.ui.components.AnimatedCircularProgressIndicator @Composable fun ProgressFragment( @@ -32,17 +29,13 @@ fun ProgressFragment( // 没有任务时 0f } - val animatedProgress by animateFloatAsState( - targetValue = progress, - animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec, - label = "To Do Progress" - ) + Box( modifier = modifier, contentAlignment = Alignment.Center ) { - CircularProgressIndicator( - progress = { animatedProgress }, + AnimatedCircularProgressIndicator( + progress = progress, strokeWidth = 10.dp, gapSize = 10.dp, modifier = Modifier.size(175.dp)