blob: dab30b2afd278b24262815fd7c79159b224ab952 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package com.ambientaddons.utils
class Timer {
private var previousTime: Long = 0
private var startTime: Long? = null
var isRunning: Boolean = false
private set
private val sessionTime: Long
get() {
return startTime?.let { System.currentTimeMillis() - it } ?: 0
}
private val time: Long
get() {
return sessionTime?.let { it + previousTime } ?: 0
}
fun start() {
isRunning = true
startTime = System.currentTimeMillis()
}
fun stop() {
isRunning = false
previousTime = sessionTime
startTime = null
}
}
|