android-ktx
android-ktx copied to clipboard
CountDownTimer top-level function
I think most of the time folks use CountDownTimer with 1s interval and only onTick callback. So we could use a default parameter for interval (also probably for starting the timer) and a lambda as last parameter for onTick. With that the following top-level function might exist:
fun countDownTimer(
millisInFuture: Long,
interval: Long = 1000,
start: Boolean = true,
onFinish: () -> Unit = {},
onTick: (Long) -> Unit
): CountDownTimer
And the usage is a lot simplified after that:
val timer = countDownTimer(10_000) {
// onTick
// it - the amount of time until finished.
}
What do you think about this?