fix RandomBg start interval

This commit is contained in:
Milos Kozak 2021-11-29 18:06:39 +01:00
parent 3ee1a3a9d8
commit 7f3f1c6c8b

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.source
import android.os.Handler
import android.os.HandlerThread
import android.os.SystemClock
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
@ -74,7 +75,11 @@ class RandomBgPlugin @Inject constructor(
override fun onStart() {
super.onStart()
handler.postDelayed(refreshLoop, T.mins(interval).msecs())
val cal = GregorianCalendar()
cal[Calendar.MILLISECOND] = 0
cal[Calendar.SECOND] = 0
cal[Calendar.MINUTE] -= cal[Calendar.MINUTE] % 5
handler.postAtTime(refreshLoop, SystemClock.uptimeMillis() + cal.timeInMillis + T.mins(5).msecs() + 1000 - System.currentTimeMillis())
disposable.clear()
}