Skip to content

Commit b4f6c40

Browse files
committed
🔨 UNT-T5677 Code Refactor.
1 parent 84ab012 commit b4f6c40

File tree

15 files changed

+619
-662
lines changed

15 files changed

+619
-662
lines changed

app/src/main/java/com/simform/ssloadingbuttonandroid/JoinButton.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/src/main/java/com/simform/ssloadingbuttonandroid/MainActivity.kt

Lines changed: 174 additions & 441 deletions
Large diffs are not rendered by default.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.simform.ssloadingbuttonandroid.ssbutton
2+
3+
import androidx.compose.animation.animateColor
4+
import androidx.compose.animation.core.*
5+
import androidx.compose.runtime.getValue
6+
import androidx.compose.runtime.*
7+
import androidx.compose.ui.graphics.Color
8+
import androidx.compose.ui.unit.Dp
9+
10+
object Animation {
11+
@Composable
12+
fun ssRepeatedFloatAnimation(
13+
initialValue: Float,
14+
targetValue: Float,
15+
durationMillis: Int
16+
): Float {
17+
val repeatedFloat by rememberInfiniteTransition().animateValue(
18+
initialValue = initialValue,
19+
targetValue = targetValue,
20+
typeConverter = Float.VectorConverter,
21+
animationSpec = infiniteRepeatable(
22+
animation = tween(durationMillis, easing = LinearEasing),
23+
repeatMode = RepeatMode.Restart
24+
)
25+
)
26+
return repeatedFloat
27+
}
28+
@Composable
29+
fun ssRepeatedDpAnimation(initialValue: Dp, targetValue: Dp, durationMillis: Int): Dp {
30+
val repeatedDp by rememberInfiniteTransition().animateValue(
31+
initialValue = initialValue,
32+
targetValue = targetValue,
33+
typeConverter = Dp.VectorConverter,
34+
animationSpec = infiniteRepeatable(
35+
animation = tween(durationMillis, easing = LinearEasing),
36+
repeatMode = RepeatMode.Reverse
37+
)
38+
)
39+
return repeatedDp
40+
}
41+
@Composable
42+
fun ssRepeatedColorAnimation(initialValue: Color, targetValue: Color, durationMillis: Int): Color {
43+
val repeatedColor by rememberInfiniteTransition().animateColor(
44+
initialValue = initialValue,
45+
targetValue = targetValue,
46+
animationSpec = infiniteRepeatable(
47+
animation = tween(durationMillis, easing = LinearEasing),
48+
repeatMode = RepeatMode.Restart
49+
)
50+
)
51+
return repeatedColor
52+
}
53+
@Composable
54+
fun sizeAnimationMethod(targetValue: Dp, durationMillis: Int): Dp {
55+
val size by animateDpAsState(
56+
targetValue = targetValue,
57+
tween(
58+
durationMillis = durationMillis,
59+
easing = LinearOutSlowInEasing
60+
)
61+
)
62+
return size
63+
}
64+
@Composable
65+
fun ssAnimateIntAsState(targetValue: Int, durationMillis: Int): Int {
66+
val newValue by animateIntAsState(targetValue, animationSpec = tween(durationMillis))
67+
return newValue
68+
}
69+
@Composable
70+
fun ssAnimateFloatAsState(targetValue: Float, durationMillis: Int): Float {
71+
val newValue by animateFloatAsState(targetValue, animationSpec = tween(durationMillis))
72+
return newValue
73+
}
74+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.simform.ssloadingbuttonandroid.ssbutton
2+
3+
import androidx.compose.foundation.Canvas
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.Modifier
6+
import androidx.compose.ui.geometry.Offset
7+
import androidx.compose.ui.graphics.Color
8+
import androidx.compose.ui.graphics.StrokeCap
9+
import androidx.compose.ui.graphics.drawscope.withTransform
10+
import androidx.compose.ui.unit.Dp
11+
import androidx.compose.ui.unit.dp
12+
import com.simform.ssloadingbuttonandroid.ssbutton.Animation.ssRepeatedFloatAnimation
13+
import com.simform.ssloadingbuttonandroid.utils.*
14+
15+
object ClockLoadingBar {
16+
@Composable
17+
fun Clock(modifier: Modifier = Modifier, color: Color, minHeightWidth: Dp) {
18+
val progressRotation = ssRepeatedFloatAnimation(
19+
initialValue = zeroFloat,
20+
targetValue = oneFloat,
21+
durationMillis = MINUTE_DURATION
22+
)
23+
val progressHourRotation = ssRepeatedFloatAnimation(
24+
initialValue = zeroFloat,
25+
targetValue = oneFloat,
26+
durationMillis = HOUR_DURATION
27+
)
28+
Canvas(modifier = modifier) {
29+
val middle = Offset(size.minDimension / two, size.minDimension / two)
30+
withTransform(
31+
{
32+
rotate(threeSixtyFloat * progressRotation, middle)
33+
}, {
34+
drawLine(
35+
strokeWidth = six.dp.toPx(),
36+
cap = StrokeCap.Round,
37+
color = color,
38+
start = middle,
39+
end = Offset(size.minDimension / two, (minHeightWidth/ two - ten.dp).toPx())
40+
)
41+
}
42+
)
43+
withTransform(
44+
{
45+
rotate(threeSixtyFloat * progressHourRotation, middle)
46+
}, {
47+
drawLine(
48+
strokeWidth = six.dp.toPx(),
49+
cap = StrokeCap.Round,
50+
color = Color.Black,
51+
start = middle,
52+
end = Offset(size.minDimension / two, (minHeightWidth/ two - thirteen.dp).toPx())
53+
)
54+
}
55+
)
56+
}
57+
}
58+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.simform.ssloadingbuttonandroid.ssbutton
2+
3+
import androidx.compose.foundation.layout.size
4+
import androidx.compose.material.CircularProgressIndicator
5+
import androidx.compose.material.Icon
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.draw.rotate
9+
import androidx.compose.ui.graphics.Color
10+
import androidx.compose.ui.graphics.graphicsLayer
11+
import androidx.compose.ui.res.painterResource
12+
import androidx.compose.ui.unit.Dp
13+
import androidx.compose.ui.unit.dp
14+
import com.simform.ssloadingbuttonandroid.R
15+
import com.simform.ssloadingbuttonandroid.ssbutton.Animation.ssRepeatedDpAnimation
16+
import com.simform.ssloadingbuttonandroid.ssbutton.Animation.ssRepeatedFloatAnimation
17+
import com.simform.ssloadingbuttonandroid.ssbutton.ClockLoadingBar.Clock
18+
import com.simform.ssloadingbuttonandroid.utils.ten
19+
import com.simform.ssloadingbuttonandroid.utils.three
20+
import com.simform.ssloadingbuttonandroid.utils.threeSixtyFloat
21+
import com.simform.ssloadingbuttonandroid.utils.zeroFloat
22+
23+
object PrintLoadingBar {
24+
@Composable
25+
fun printLoadingBar(type: SSButtonType, progressAlpha: Float, assetColor: Color, minHeightWidth: Dp, durationMillis: Int) {
26+
when (type) {
27+
SSButtonType.ROUNDED_PROGRESS -> {
28+
CircularProgressIndicator(
29+
modifier = Modifier
30+
.graphicsLayer(alpha = progressAlpha).size(minHeightWidth- ten.dp),
31+
color = assetColor,
32+
strokeWidth = three.dp
33+
)
34+
}
35+
SSButtonType.WHEEL -> {
36+
Icon(
37+
painter = painterResource(id = R.drawable.icon),
38+
contentDescription = null,
39+
modifier = Modifier
40+
.size(minHeightWidth - ten.dp)
41+
.graphicsLayer { alpha = progressAlpha }
42+
.rotate(ssRepeatedFloatAnimation(zeroFloat, threeSixtyFloat, durationMillis)),
43+
tint = assetColor
44+
)
45+
}
46+
SSButtonType.ZOOM_IN_OUT_PROGRESS -> {
47+
CircularProgressIndicator(
48+
modifier = Modifier
49+
.graphicsLayer(alpha = progressAlpha)
50+
.size(ssRepeatedDpAnimation(initialValue = minHeightWidth - ten.dp, targetValue = ten.dp, durationMillis = durationMillis)),
51+
color = assetColor,
52+
strokeWidth = three.dp
53+
)
54+
}
55+
SSButtonType.CLOCK -> {
56+
Clock(modifier = Modifier
57+
.graphicsLayer { alpha = progressAlpha }, color = assetColor, minHeightWidth = minHeightWidth
58+
)
59+
}
60+
SSButtonType.SPIRAL -> {
61+
Icon(
62+
painter = painterResource(id = R.drawable.spiral),
63+
contentDescription = null,
64+
modifier = Modifier
65+
.size(minHeightWidth - ten.dp)
66+
.graphicsLayer { alpha = progressAlpha }
67+
.rotate(ssRepeatedFloatAnimation(initialValue = threeSixtyFloat, targetValue = zeroFloat, durationMillis = durationMillis)),
68+
tint = assetColor
69+
)
70+
}
71+
}
72+
}
73+
}

app/src/main/java/com/simform/ssloadingbuttonandroid/ButtonState.kt renamed to app/src/main/java/com/simform/ssloadingbuttonandroid/ssbutton/SSButtonState.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.simform.ssloadingbuttonandroid
1+
package com.simform.ssloadingbuttonandroid.ssbutton
22

33

4-
enum class ButtonStateList {
4+
enum class SSButtonState {
55
IDLE, LOADING, SUCCESS, FAILIURE
66
}
77

8-
enum class ButtonType {
8+
enum class SSButtonType {
99
ROUNDED_PROGRESS, WHEEL, ZOOM_IN_OUT_PROGRESS, CLOCK, SPIRAL
1010
}

0 commit comments

Comments
 (0)