Skip to content

Commit 6460085

Browse files
authored
nate/feature/LOOP-1293/display-mock-cgm-status-progress (#134)
* displaying the cgm status progress * defining color for glucose, trend, and progress * display LOW and HIGH for out of range glucose measurements * responses to PR comments
1 parent 8c011b5 commit 6460085

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

Loop/View Controllers/StatusTableViewController.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,14 @@ final class StatusTableViewController: ChartsTableViewController {
507507
unit: unit,
508508
staleGlucoseAge: self.deviceManager.loopManager.settings.inputDataRecencyInterval,
509509
sensor: self.deviceManager.sensorState)
510-
511-
if self.deviceManager.cgmManager != nil {
512-
hudView.cgmStatusHUD.presentStatusHighlight((self.deviceManager.cgmManager as? CGMManagerUI)?.cgmStatusHighlight)
513-
}
514510
}
515511

512+
if self.deviceManager.cgmManager != nil {
513+
hudView.cgmStatusHUD.presentStatusHighlight((self.deviceManager.cgmManager as? CGMManagerUI)?.cgmStatusHighlight)
514+
}
515+
516+
hudView.cgmStatusHUD.lifecycleProgress = (self.deviceManager.cgmManager as? CGMManagerUI)?.cgmLifecycleProgress
517+
516518
// Pump Status HUD
517519
if self.deviceManager.pumpManager != nil {
518520
hudView.pumpStatusHUD.presentStatusHighlight(self.pumpStatusHighlight)

LoopUI/ViewModel/CGMStatusHUDViewModel.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public class CGMStatusHUDViewModel {
2121

2222
var accessibilityString: String = ""
2323

24-
var tintColor: UIColor?
24+
var glucoseValueTintColor: UIColor = .label
25+
26+
var glucoseTrendTintColor: UIColor = .systemPurple
2527

2628
var staleGlucoseValueHandler: (String) -> Void
2729

@@ -83,8 +85,15 @@ public class CGMStatusHUDViewModel {
8385
let numberFormatter = NumberFormatter.glucoseFormatter(for: unit)
8486
if let valueString = numberFormatter.string(from: glucoseQuantity) {
8587
if glucoseValueCurrent {
86-
glucoseValueString = valueString
8788
startStalenessTimerIfNeeded()
89+
switch sensor?.glucoseValueType {
90+
case .some(.belowRange):
91+
glucoseValueString = LocalizedString("LOW", comment: "String displayed instead of a glucose value below the CGM range")
92+
case .some(.aboveRange):
93+
glucoseValueString = LocalizedString("HIGH", comment: "String displayed instead of a glucose value above the CGM range")
94+
default:
95+
glucoseValueString = valueString
96+
}
8897
} else {
8998
glucoseValueString = CGMStatusHUDViewModel.staleGlucoseRepresentation
9099
}
@@ -98,7 +107,8 @@ public class CGMStatusHUDViewModel {
98107
trend = nil
99108
}
100109

101-
tintColor = sensor?.glucoseValueType?.color
110+
glucoseValueTintColor = sensor?.glucoseValueType?.glucoseColor ?? .label
111+
glucoseTrendTintColor = sensor?.glucoseValueType?.trendColor ?? .systemPurple
102112

103113
unitsString = unit.localizedShortUnitString
104114
accessibilityString = accessibilityStrings.joined(separator: ", ")

LoopUI/Views/CGMStatusHUDView.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,18 @@ public final class CGMStatusHUDView: DeviceStatusHUDView, NibLoadable {
5353
public override func tintColorDidChange() {
5454
super.tintColorDidChange()
5555

56-
glucoseValueHUD.tintColor = tintColor
57-
switch tintColor {
58-
case UIColor.label:
59-
glucoseTrendHUD.tintColor = .systemPurple
60-
default:
61-
glucoseTrendHUD.tintColor = tintColor
62-
}
56+
glucoseValueHUD.tintColor = viewModel.glucoseValueTintColor
57+
glucoseTrendHUD.tintColor = viewModel.glucoseTrendTintColor
6358
}
6459

6560
public func presentAddCGMHighlight() {
61+
resetProgress()
6662
presentStatusHighlight(withMessage: LocalizedString("Add CGM", comment: "Title text for button to set up a CGM"),
6763
icon: UIImage(systemName: "plus.circle")!,
6864
color: .systemBlue)
6965
}
7066

71-
override public func presentStatusHighlight() {
67+
override func presentStatusHighlight() {
7268
guard statusStackView.arrangedSubviews.contains(glucoseValueHUD),
7369
statusStackView.arrangedSubviews.contains(glucoseTrendHUD) else
7470
{
@@ -111,8 +107,11 @@ public final class CGMStatusHUDView: DeviceStatusHUDView, NibLoadable {
111107

112108
glucoseValueHUD.glucoseLabel.text = viewModel.glucoseValueString
113109
glucoseValueHUD.unitLabel.text = viewModel.unitsString
110+
glucoseValueHUD.tintColor = viewModel.glucoseValueTintColor
111+
114112
glucoseTrendHUD.setTrend(viewModel.trend)
115-
tintColor = viewModel.tintColor ?? .label
116-
accessibilityValue = viewModel.accessibilityString
113+
glucoseTrendHUD.tintColor = viewModel.glucoseTrendTintColor
114+
115+
accessibilityValue = viewModel.accessibilityString
117116
}
118117
}

LoopUI/Views/DeviceStatusHUDView.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import LoopKitUI
2222
@IBOutlet public weak var progressView: UIProgressView! {
2323
didSet {
2424
progressView.isHidden = true
25+
progressView.tintColor = .systemPurple
2526
}
2627
}
2728

@@ -34,6 +35,24 @@ import LoopKitUI
3435

3536
@IBOutlet public weak var statusStackView: UIStackView!
3637

38+
public var lifecycleProgress: DeviceLifecycleProgress? {
39+
didSet {
40+
guard let lifecycleProgress = lifecycleProgress else {
41+
resetProgress()
42+
return
43+
}
44+
45+
progressView.isHidden = false
46+
progressView.progress = Float(lifecycleProgress.percentComplete.clamped(to: 0...1))
47+
progressView.tintColor = lifecycleProgress.progressState.color
48+
}
49+
}
50+
51+
public func resetProgress() {
52+
progressView.isHidden = true
53+
progressView.progress = 0
54+
}
55+
3756
func setup() {
3857
if statusHighlightView == nil {
3958
statusHighlightView = StatusHighlightHUDView(frame: self.frame)
@@ -72,4 +91,5 @@ import LoopKitUI
7291
statusHighlightView.isHidden = true
7392
statusStackView?.removeArrangedSubview(statusHighlightView)
7493
}
94+
7595
}

0 commit comments

Comments
 (0)