mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
fix: add CallDurationHelper to keep track of call duration
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user