use the call's details to calculate the call duration

This commit is contained in:
Mysochenko Yuriy
2022-05-09 13:03:18 +03:00
parent c7c2d9108a
commit 330ef1efbc
5 changed files with 21 additions and 55 deletions

View File

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

View File

@ -104,5 +104,13 @@ class CallManager {
}
}
}
fun getCallDuration(): Int {
return if (call != null) {
((System.currentTimeMillis() - call!!.details.connectTimeMillis) / 1000).toInt()
} else {
0
}
}
}
}