android-ktx icon indicating copy to clipboard operation
android-ktx copied to clipboard

CountDownTimer top-level function

Open romtsn opened this issue 7 years ago • 0 comments

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?

romtsn avatar May 13 '18 10:05 romtsn