🤵♂️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import java.io.IOException | |
suspend fun <T> retryIO( | |
times: Int = Int.MAX_VALUE, | |
initialDelay: Long = 100, // 0.1 second | |
maxDelay: Long = 1000, // 1 second | |
factor: Double = 2.0, | |
block: suspend () -> T | |
): T { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import kotlinx.coroutines.flow.* | |
import java.io.IOException | |
import kotlin.math.pow | |
fun <T> Flow<T>.retryWithExponentialBackoff( | |
times: Int, | |
initialDelay: Long, | |
factor: Double | |
): Flow<T> = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LaunchedEffect(greyAnimate,yellowAnimate,redAnimate,greenAnimate,redAnimate) { | |
launch { | |
greenAnimate.animateTo( | |
targetValue = 1f, | |
animationSpec = tween(durationMillis = 3000, easing = LinearEasing)) | |
yellowAnimate.animateTo( | |
targetValue = 1f, | |
animationSpec = tween(durationMillis = 3000, easing = LinearEasing)) | |
redAnimate.animateTo( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.composelearning.graphics | |
import androidx.compose.animation.core.Animatable | |
import androidx.compose.animation.core.AnimationVector1D | |
import androidx.compose.animation.core.tween | |
import androidx.compose.foundation.Canvas | |
import androidx.compose.foundation.clickable | |
import androidx.compose.foundation.gestures.detectTapGestures | |
import androidx.compose.foundation.layout.BoxWithConstraints |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalMaterialApi | |
@Composable | |
fun Tutorial2_13Screen() { | |
val viewModel = MyViewModel() | |
TutorialContent(viewModel) | |
} | |
@ExperimentalMaterialApi | |
@Composable | |
private fun TutorialContent(viewModel: MyViewModel) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.composelearning.lists | |
import androidx.compose.animation.core.Animatable | |
import androidx.compose.animation.core.FloatSpringSpec | |
import androidx.compose.animation.core.Spring | |
import androidx.compose.animation.core.calculateTargetValue | |
import androidx.compose.animation.splineBasedDecay | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.gestures.awaitFirstDown | |
import androidx.compose.foundation.gestures.horizontalDrag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Stable | |
interface CircularRowState { | |
val horizontalOffset: Float | |
val firstVisibleItem: Int | |
val lastVisibleItem: Int | |
val scaleX: Float | |
val scaleY: Float | |
val alphaValue: Float | |
suspend fun snapTo(value: Float) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val canvasWidth = size.width.toDp() | |
// calculate the progress for each color | |
val progressGreen = 40 | |
val greenSize = (canvasWidth * progressGreen) / 100 | |
val progressYellow = 20 | |
val yellowSize = (canvasWidth * progressYellow) / 100 | |
val progressRed = 15 | |
val redSize = (canvasWidth * progressRed) / 100 | |
val progressGray = 5 | |
val graySize = (canvasWidth * progressGray) / 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LaunchedEffect(greyAnimate,yellowAnimate,redAnimate,greenAnimate,redAnimate) { | |
launch { | |
greenAnimate.animateTo( | |
targetValue = 1f, | |
animationSpec = tween(durationMillis = 3000, easing = LinearEasing)) | |
yellowAnimate.animateTo( | |
targetValue = 1f, | |
animationSpec = tween(durationMillis = 3000, easing = LinearEasing)) | |
redAnimate.animateTo( | |
targetValue = 1f, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drawRect( | |
color = Color(0xFFFEC93E), | |
topLeft = Offset(greenSize.toPx(), 0f), | |
size = Size(yellowSize.toPx(), 8.dp.toPx()) | |
) | |
//draw red progress with offset = yellow progress + green progress | |
drawRect( | |
color = Color(0xFFED5554), | |
topLeft = Offset(greenSize.toPx() + yellowSize.toPx(), 0f), |
NewerOlder