Skip to content

Commit

Permalink
Merge pull request #285 from loopandlearn/indicate-stale-badge-data2
Browse files Browse the repository at this point in the history
Clear badge counter if bg data is stale
  • Loading branch information
marionbarker committed Apr 24, 2024
2 parents bf3c12a + dbe7bce commit 5a2d88a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 5 additions & 2 deletions LoopFollow/Controllers/Nightscout/BGData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ extension MainViewController {
self.startBGTimer(time: 300 - secondsAgo + Double(UserDefaultsRepository.bgUpdateDelay.value))
let timerVal = 310 - secondsAgo
print("##### started 5:10 bg timer: \(timerVal)")
self.updateBadge(val: data[0].sgv)
self.evaluateSpeakConditions(currentValue: data[0].sgv, previousValue: data[1].sgv)
if data.count > 1 {
self.evaluateSpeakConditions(currentValue: data[0].sgv, previousValue: data[1].sgv)
}
}
}

Expand Down Expand Up @@ -276,8 +277,10 @@ extension MainViewController {
attributeString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSRange(location: 0, length: attributeString.length))
if deltaTime >= 12 { // Data is stale
attributeString.addAttribute(.strikethroughColor, value: UIColor.systemRed, range: NSRange(location: 0, length: attributeString.length))
self.updateBadge(val: 0)
} else { // Data is fresh
attributeString.addAttribute(.strikethroughColor, value: UIColor.clear, range: NSRange(location: 0, length: attributeString.length))
self.updateBadge(val: latestBG)
}
self.BGText.attributedText = attributeString

Expand Down
6 changes: 2 additions & 4 deletions LoopFollow/ViewControllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,11 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
}

func updateBadge(val: Int) {
DispatchQueue.main.async {
if UserDefaultsRepository.appBadge.value {
let latestBG = String(val)
UIApplication.shared.applicationIconBadgeNumber = Int(bgUnits.removePeriodAndCommaForBadge(bgUnits.toDisplayUnits(latestBG))) ?? val
} else {
UIApplication.shared.applicationIconBadgeNumber = 0
}
} else {
UIApplication.shared.applicationIconBadgeNumber = 0
}
}

Expand Down

0 comments on commit 5a2d88a

Please sign in to comment.