fix: add CallDurationHelper to keep track of call duration

This commit is contained in:
darthpaul
2021-09-20 00:27:03 +01:00
parent bdab26838e
commit 2f9341dd33
4 changed files with 53 additions and 23 deletions

View File

@ -0,0 +1,32 @@
package com.simplemobiletools.dialer.helpers
import java.util.Timer
import java.util.TimerTask
class CallDurationHelper {
private var callTimer = Timer()
private var callDuration = 0
private var callback: ((durationSecs: Int) -> Unit)? = null
fun onDurationChange(callback: (durationSecs: Int) -> Unit) {
this.callback = callback
}
fun start() {
try {
callTimer.scheduleAtFixedRate(getTimerUpdateTask(), 1000, 1000)
} catch (ignored: Exception) {
}
}
fun cancel() {
callTimer.cancel()
}
private fun getTimerUpdateTask() = object : TimerTask() {
override fun run() {
callDuration++
callback?.invoke(callDuration)
}
}
}