Nat Strangerweather
06/29/2024, 4:51 PMisBeingProcessed
that triggers a loading animation when the wallpaper is being set, and then stops on completion. This Boolean is only ever taken into account if I add a short delay at the start of the coroutine. The problem is that the delay also freezes my loading animation. How could I do this correctly? 🧵Nat Strangerweather
06/29/2024, 4:51 PM"Set as scrolling wallpaper" -> {
isBeingProcessed = true
scope.launch {
wallpaperManager.setBitmap(
bmp, null, true, flags
)
}.invokeOnCompletion {
isBeingProcessed = false
isSheetOpen = false
Toast.makeText(
context,
"Wallpaper set successfully",
Toast.LENGTH_SHORT
).show()
}
}
Stylianos Gakis
06/29/2024, 4:56 PMisBeingProcessed
a MutableState? Probably worth showing a bit more code around this.Nat Strangerweather
06/29/2024, 5:05 PMvar isBeingProcessed by rememberSaveable { mutableStateOf(false) }
Nat Strangerweather
06/29/2024, 5:05 PMNat Strangerweather
06/29/2024, 5:06 PMif (isBeingProcessed) {
Dialog(onDismissRequest = {}) {
LoadingAnimation()
}
}
Nat Strangerweather
06/29/2024, 5:08 PM"Set as cropped wallpaper" ->
(context as? ComponentActivity)?.let { activity ->
scope.launch {
isBeingProcessed = true
setWallpaperWithPosition(
activity,
wallpaperManager,
bmp,
flags
)
}.invokeOnCompletion {
isBeingProcessed = false
isSheetOpen = false
Toast.makeText(
context,
"Wallpaper set successfully",
Toast.LENGTH_SHORT
).show()
}
} ?: run {
// Handle the case where context is not a ComponentActivity
isBeingProcessed = false
isSheetOpen = false
Toast.makeText(
context,
"Failed to set wallpaper",
Toast.LENGTH_SHORT
).show()
}
Stylianos Gakis
06/29/2024, 5:34 PMNat Strangerweather
06/29/2024, 5:42 PMisBeingProcessed = true
scope.launch {
delay(500)
wallpaperManager.setBitmap(
bmp, null, true, flags
)
}
Nat Strangerweather
06/29/2024, 5:44 PMNat Strangerweather
06/29/2024, 5:44 PMStylianos Gakis
06/29/2024, 5:53 PMlaunch(Dispatchers.Default)
so the wallpaper stuff does not run on the main thread, does that change anything?Nat Strangerweather
06/29/2024, 5:54 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>) {
and it is working as it shouldNat Strangerweather
06/29/2024, 5:56 PMlaunch(Dispatchers.Default)
works well.Nat Strangerweather
06/29/2024, 5:56 PMStylianos Gakis
06/30/2024, 12:53 AMNat Strangerweather
06/30/2024, 8:15 PM