So I'm just getting back to Android development after being away from it for several years, and of course, it's vastly different now, what with Jetpack Compose being the hot new stuff now.
I'm kicking off a Kotlin coroutine that is a long process, but one that I can calculate its progress precisely. I want to show a LinearProgressIndicator
in my @Composable view (the one that kicked off the coroutine), but I can't figure out the correct terms to search for to figure out how to pass the progress from the coroutine back into the @Composable view to update the progress indicator in real-time.
Edit/update: I'm going to try to re-phrase my question with code:
In my @Composable view, I'm kicking off a long-running, but measurable task:
@Composable
fun ConfigureFilesScreen() {
var copyProgress by remember { mutableStateOf(0f) }
var copyTotal by remember { mutableStateOf(0L) }
var copyCompleted by remember { mutableStateOf (0L)}
...
LinearProgressIndicator(progress = copyProgress)
...
LaunchedEffect(key1 = true) {
copyTotal = preflightFiles()
failedReason = processFiles()
}
copyProgress
is calculated by copyCompleted / copyTotal
; processFiles()
knows how much processing has been done, which is the data with which I want to update the progress value of the LinearProgressIndicator
view. It is defined thusly:
private suspend fun processFiles(): String? {
...
}
How do pass the variables/values between processFiles()
(NOT a @Composable function) and ConfigureFilesScreen()
(IS a @Composable function) such that the latter updates the progress
value of the LinearProgressIndicator
?