better handle missed bg readings
This commit is contained in:
parent
8fe7e7ce2b
commit
6663b9db4f
|
@ -1,16 +1,16 @@
|
|||
package info.nightscout.androidaps.utils
|
||||
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.ValueWrapper
|
||||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.IobCobCalculator
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -39,7 +39,6 @@ class LocalAlertUtils @Inject constructor(
|
|||
private val resourceHelper: ResourceHelper,
|
||||
private val activePlugin: ActivePlugin,
|
||||
private val profileFunction: ProfileFunction,
|
||||
private val iobCobCalculator: IobCobCalculator,
|
||||
private val smsCommunicatorPlugin: SmsCommunicatorPlugin,
|
||||
private val config: Config,
|
||||
private val repository: AppRepository,
|
||||
|
@ -117,9 +116,12 @@ class LocalAlertUtils @Inject constructor(
|
|||
}
|
||||
|
||||
fun checkStaleBGAlert() {
|
||||
val bgReading = iobCobCalculator.ads.lastBg()
|
||||
val bgReadingWrapped = repository.getLastGlucoseValueWrapped().blockingGet()
|
||||
val bgReading = if (bgReadingWrapped is ValueWrapper.Existing) bgReadingWrapped.value else return
|
||||
if (sp.getBoolean(R.string.key_enable_missed_bg_readings_alert, false)
|
||||
&& bgReading != null && bgReading.timestamp + missedReadingsThreshold() < System.currentTimeMillis() && sp.getLong("nextMissedReadingsAlarm", 0L) < System.currentTimeMillis()) {
|
||||
&& bgReading.timestamp + missedReadingsThreshold() < System.currentTimeMillis()
|
||||
&& sp.getLong("nextMissedReadingsAlarm", 0L) < System.currentTimeMillis()
|
||||
) {
|
||||
val n = Notification(Notification.BG_READINGS_MISSED, resourceHelper.gs(R.string.missed_bg_readings), Notification.URGENT)
|
||||
n.soundId = R.raw.alarm
|
||||
sp.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold())
|
||||
|
@ -128,6 +130,8 @@ class LocalAlertUtils @Inject constructor(
|
|||
if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
|
||||
n.text?.let { disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(it)).subscribe() }
|
||||
}
|
||||
} else if (dateUtil.isOlderThan(bgReading.timestamp, 5).not()) {
|
||||
rxBus.send(EventDismissNotification(Notification.BG_READINGS_MISSED))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue