I need to implement a countdown timer in a Glance widget, that should be updated every second. At the bare minimum, every minute.
What would be the best approach for this using Jetpack Compose Glance widgets? First time I play with this.
I’ve been trying to do something like
object : CountDownTimer(startTime, 1000) {
private var coroutineScope: CoroutineScope? = null
override fun onTick(millisUntilFinished: Long) {
if (coroutineScope == null) {
coroutineScope = CoroutineScope(coroutineContext)
}
coroutineScope?.launch {
onTick?.invoke(millisUntilFinished) // calls GlanceWidget.updateAll(context)
}
}
override fun onFinish() {
coroutineScope?.cancel()
onFinish?.invoke()
}
}