33package com.dede.android_eggs.views.settings.compose.options
44
55import androidx.activity.compose.LocalActivity
6- import androidx.compose.animation.core.LinearEasing
76import androidx.compose.animation.core.RepeatMode
87import androidx.compose.animation.core.animateFloat
98import androidx.compose.animation.core.infiniteRepeatable
109import androidx.compose.animation.core.rememberInfiniteTransition
1110import androidx.compose.animation.core.tween
1211import androidx.compose.foundation.layout.Arrangement
13- import androidx.compose.foundation.layout.Box
1412import androidx.compose.foundation.layout.Row
1513import androidx.compose.foundation.layout.Spacer
1614import androidx.compose.foundation.layout.fillMaxWidth
@@ -30,13 +28,15 @@ import androidx.compose.material3.Text
3028import androidx.compose.material3.TextButton
3129import androidx.compose.material3.toShape
3230import androidx.compose.runtime.Composable
31+ import androidx.compose.runtime.MutableState
3332import androidx.compose.runtime.getValue
3433import androidx.compose.runtime.mutableStateOf
3534import androidx.compose.runtime.remember
3635import androidx.compose.runtime.rememberCoroutineScope
3736import androidx.compose.runtime.setValue
3837import androidx.compose.ui.Alignment
3938import androidx.compose.ui.Modifier
39+ import androidx.compose.ui.graphics.Shape
4040import androidx.compose.ui.graphics.graphicsLayer
4141import androidx.compose.ui.platform.LocalContext
4242import androidx.compose.ui.res.stringResource
@@ -60,11 +60,11 @@ import com.dede.android_eggs.resources.R as StringR
6060
6161
6262@Composable
63- fun VersionOption () {
63+ fun VersionOption (shape : Shape = OptionShapes .defaultShape ) {
6464 val context = LocalContext .current
6565 val (versionName, versionCode) = remember(context) { Utils .getAppVersionPair(context) }
6666 Option (
67- shape = OptionShapes .firstShape() ,
67+ shape = shape ,
6868 leadingIcon = imageVectorIconBlock(imageVector = Icons .Outlined .NewReleases ),
6969 title = stringResource(R .string.label_version, versionName, versionCode),
7070 desc = AGPUtils .getVcsRevision(7 ),
@@ -90,66 +90,57 @@ fun VersionOption() {
9090 )
9191}
9292
93+ private val newVersionState: MutableState <LatestVersion ?> = mutableStateOf(null )
94+
9395@Composable
9496private fun UpgradeIconButton () {
95- var newVersion: LatestVersion ? by remember { mutableStateOf(null ) }
96- Box (
97- modifier = Modifier .offset(x = 4 .dp),// fix padding end of Option
98- contentAlignment = Alignment .Center
99- ) {
100- val context = LocalContext .current
101- val activity = LocalActivity .current
102- val coroutineScope = rememberCoroutineScope()
97+ var newVersion: LatestVersion ? by remember { newVersionState }
10398
104- var iconButtonAnimatable by remember { mutableStateOf(true ) }
105- val infiniteTransition =
106- rememberInfiniteTransition(label = " UpgradeIconButtonInfiniteTransition" )
107- val scale by infiniteTransition.animateFloat(
108- initialValue = 1f , targetValue = 1.2f ,
109- animationSpec = infiniteRepeatable(tween(1000 ), RepeatMode .Reverse )
110- )
111- val degrees by infiniteTransition.animateFloat(
112- initialValue = 0f , targetValue = 360f ,
113- animationSpec = infiniteRepeatable(
114- animation = tween(2200 , easing = LinearEasing ),
115- repeatMode = RepeatMode .Restart
116- )
117- )
118- FilledTonalIconButton (
119- modifier = Modifier .graphicsLayer {
99+ val context = LocalContext .current
100+ val activity = LocalActivity .current
101+ val coroutineScope = rememberCoroutineScope()
102+
103+ var iconButtonAnimatable by remember { mutableStateOf(true ) }
104+ val infiniteTransition =
105+ rememberInfiniteTransition(label = " UpgradeIconButtonInfiniteTransition" )
106+ val scale by infiniteTransition.animateFloat(
107+ initialValue = 1f , targetValue = 1.2f ,
108+ animationSpec = infiniteRepeatable(tween(800 ), RepeatMode .Reverse )
109+ )
110+ FilledTonalIconButton (
111+ modifier = Modifier
112+ .offset(x = 4 .dp)// fix padding end of Option
113+ .graphicsLayer {
120114 if (iconButtonAnimatable) {
121115 scaleY = scale
122116 scaleX = scale
123- rotationZ = degrees
124117 }
125118 },
126- shapes = IconButtonShapes (MaterialShapes .Cookie12Sided .toShape()),
127- onClick = onClick@{
128- if (activity == null ) {
129- iconButtonAnimatable = false
130- return @onClick
131- }
132- coroutineScope.launch {
133- val latestVersion = FlavorFeatures .get().checkUpdate(activity)
134- if (latestVersion != null ) {
135- if (compareStringVersion(
136- latestVersion.versionName,
137- Utils .getAppVersionPair(context).first
138- ) > 0
139- ) {
140- newVersion = latestVersion
141- } else {
142- context.toast(StringR .string.toast_no_update_found)
143- iconButtonAnimatable = false
144- }
119+ shapes = IconButtonShapes (MaterialShapes .Cookie12Sided .toShape()),
120+ onClick = onClick@{
121+ if (activity == null ) {
122+ iconButtonAnimatable = false
123+ return @onClick
124+ }
125+ coroutineScope.launch {
126+ val latestVersion = FlavorFeatures .get().checkUpdate(activity)
127+ if (latestVersion != null ) {
128+ if (compareStringVersion(
129+ latestVersion.versionName,
130+ Utils .getAppVersionPair(context).first
131+ ) > 0
132+ ) {
133+ newVersion = latestVersion
145134 } else {
135+ context.toast(StringR .string.toast_no_update_found)
146136 iconButtonAnimatable = false
147137 }
138+ } else {
139+ iconButtonAnimatable = false
148140 }
149141 }
150- ) {
151- // no content
152142 }
143+ ) {
153144 Icon (imageVector = Icons .Rounded .Upgrade , contentDescription = null )
154145 }
155146
0 commit comments