File tree Expand file tree Collapse file tree
app/src/main/java/com/bnyro/clock/util/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import android.os.Build
1919import android.os.Handler
2020import android.os.Looper
2121import android.os.PowerManager
22+ import android.os.SystemClock
2223import android.os.Vibrator
2324import android.text.format.DateUtils
2425import android.util.Log
@@ -45,6 +46,7 @@ class TimerService : Service() {
4546
4647 private var mediaPlayer: MediaPlayer ? = null
4748 private var isPlaying = false
49+ private var oldnow = SystemClock .elapsedRealtime()
4850 private val vibrator: Vibrator by lazy {
4951 getSystemService(Context .VIBRATOR_SERVICE ) as Vibrator
5052 }
@@ -281,17 +283,21 @@ class TimerService : Service() {
281283 }
282284
283285 private fun updateState () {
286+ val now = System .currentTimeMillis()
287+ val delta = now - oldnow
288+ oldnow = now
289+
284290 timerObjects.forEach {
285291 if (it.state.value == WatchState .RUNNING ) {
286292
287- it.currentPosition.value - = UPDATE_DELAY
288-
293+ it.currentPosition.value =
294+ (it.currentPosition.value - delta.toInt())
295+ .coerceAtLeast(0 )
289296
290297 if (Build .VERSION .SDK_INT < Build .VERSION_CODES .N ) {
291298 updateNotification(it)
292299 }
293300 }
294-
295301 }
296302 }
297303
You can’t perform that action at this time.
0 commit comments