mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
fix: recreate timer on each start and reset callDuration
This commit is contained in:
@ -4,7 +4,7 @@ import java.util.Timer
|
|||||||
import java.util.TimerTask
|
import java.util.TimerTask
|
||||||
|
|
||||||
class CallDurationHelper {
|
class CallDurationHelper {
|
||||||
private var callTimer = Timer()
|
private var callTimer: Timer? = null
|
||||||
private var callDuration = 0
|
private var callDuration = 0
|
||||||
private var callback: ((durationSecs: Int) -> Unit)? = null
|
private var callback: ((durationSecs: Int) -> Unit)? = null
|
||||||
|
|
||||||
@ -14,13 +14,15 @@ class CallDurationHelper {
|
|||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
try {
|
try {
|
||||||
callTimer.scheduleAtFixedRate(getTimerUpdateTask(), 1000, 1000)
|
callDuration = 0
|
||||||
|
callTimer = Timer()
|
||||||
|
callTimer?.scheduleAtFixedRate(getTimerUpdateTask(), 1000, 1000)
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancel() {
|
fun cancel() {
|
||||||
callTimer.cancel()
|
callTimer?.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTimerUpdateTask() = object : TimerTask() {
|
private fun getTimerUpdateTask() = object : TimerTask() {
|
||||||
|
Reference in New Issue
Block a user