mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
use the call's details to calculate the call duration
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
@ -104,5 +104,13 @@ class CallManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCallDuration(): Int {
|
||||
return if (call != null) {
|
||||
((System.currentTimeMillis() - call!!.details.connectTimeMillis) / 1000).toInt()
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user