|
|
@@ -1050,7 +1050,6 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
|
|
|
if !granted { return }
|
|
|
|
|
|
// Create Event info
|
|
|
- // eventTitle = BGText.text + " " + DirectionText.text + " " + DeltaText.text + "\nC:" + tableData[1].value + "g I:" + tableData[0].value + "u"
|
|
|
let deltaBG = self.bgData[self.bgData.count - 1].sgv - self.bgData[self.bgData.count - 2].sgv as Int
|
|
|
let deltaTime = (TimeInterval(Date().timeIntervalSince1970) - self.bgData[self.bgData.count - 1].date) / 60
|
|
|
var deltaString = ""
|
|
|
@@ -1062,9 +1061,39 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
|
|
|
deltaString = "+" + String(deltaBG)
|
|
|
}
|
|
|
let direction = self.bgDirectionGraphic(self.bgData[self.bgData.count - 1].direction ?? "")
|
|
|
+
|
|
|
+
|
|
|
var eventStartDate = Date(timeIntervalSince1970: self.bgData[self.bgData.count - 1].date)
|
|
|
var eventEndDate = eventStartDate.addingTimeInterval(60 * 10)
|
|
|
- var eventTitle = ""
|
|
|
+ var eventTitle = UserDefaultsRepository.watchLine1.value + "\n" + UserDefaultsRepository.watchLine2.value
|
|
|
+ eventTitle = eventTitle.replacingOccurrences(of: "%BG%", with: String(self.bgData[self.bgData.count - 1].sgv))
|
|
|
+ eventTitle = eventTitle.replacingOccurrences(of: "%DIRECTION%", with: direction)
|
|
|
+ eventTitle = eventTitle.replacingOccurrences(of: "%DELTA%", with: deltaString)
|
|
|
+ var minAgo = ""
|
|
|
+ if deltaTime > 5 {
|
|
|
+ // write old BG reading and continue pushing out end date to show last entry
|
|
|
+ minAgo = String(Int(deltaTime)) + " min"
|
|
|
+ eventEndDate = eventStartDate.addingTimeInterval((60 * 10) + (deltaTime * 60))
|
|
|
+ }
|
|
|
+ var cob = "0"
|
|
|
+ if self.tableData[1].value != "" {
|
|
|
+ cob = self.tableData[1].value
|
|
|
+ }
|
|
|
+ var basal = "~"
|
|
|
+ if self.tableData[2].value != "" {
|
|
|
+ basal = self.tableData[2].value
|
|
|
+ }
|
|
|
+ var iob = "0"
|
|
|
+ if self.tableData[0].value != "" {
|
|
|
+ iob = self.tableData[0].value
|
|
|
+ }
|
|
|
+ eventTitle = eventTitle.replacingOccurrences(of: "%MINAGO%", with: minAgo)
|
|
|
+ eventTitle = eventTitle.replacingOccurrences(of: "%IOB%", with: self.tableData[0].value)
|
|
|
+ eventTitle = eventTitle.replacingOccurrences(of: "%COB%", with: cob)
|
|
|
+ eventTitle = eventTitle.replacingOccurrences(of: "%BASAL%", with: basal)
|
|
|
+
|
|
|
+ // old
|
|
|
+ /*
|
|
|
eventTitle += String(self.bgData[self.bgData.count - 1].sgv) + " "
|
|
|
eventTitle += direction + " "
|
|
|
eventTitle += deltaString + " "
|
|
|
@@ -1081,6 +1110,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
|
|
|
if self.tableData[0].value != "" {
|
|
|
eventTitle += "I: " + self.tableData[0].value + "u"
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1129,7 +1159,9 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
|
|
|
clearOldSnoozes()
|
|
|
|
|
|
// Exit if all is snoozed
|
|
|
+ // still send persistent notification with all snoozed
|
|
|
if UserDefaultsRepository.alertSnoozeAllIsSnoozed.value {
|
|
|
+ persistentNotification(bgTime: currentBGTime)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -1299,6 +1331,9 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // still send persistent notification if no alarms trigger and persistent notification is on
|
|
|
+ persistentNotification(bgTime: currentBGTime)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func triggerAlarm(sound: String, snooozedBGReadingTime: TimeInterval?)
|
|
|
@@ -1314,6 +1349,14 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
|
|
|
AlarmSound.play()
|
|
|
}
|
|
|
|
|
|
+ func persistentNotification(bgTime: TimeInterval)
|
|
|
+ {
|
|
|
+ if UserDefaultsRepository.persistentNotification.value && bgTime > UserDefaultsRepository.persistentNotificationLastBGTime.value {
|
|
|
+ guard let snoozer = self.tabBarController!.viewControllers?[2] as? SnoozeViewController else { return }
|
|
|
+ snoozer.sendNotification(self, bgVal: BGText.text ?? "", directionVal: DirectionText.text ?? "", deltaVal: DeltaText.text ?? "", minAgoVal: MinAgoText.text ?? "", alertLabelVal: "Latest BG")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
func clearOldSnoozes(){
|
|
|
let date = Date()
|
|
|
let now = date.timeIntervalSince1970
|