Skip to content

Commit 0032c31

Browse files
authored
Displaying an indicator for glucose values downloaded from Share (#202)
1 parent 5c8a113 commit 0032c31

File tree

8 files changed

+68
-18
lines changed

8 files changed

+68
-18
lines changed

Loop/Base.lproj/Main.storyboard

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
1919
<prototypes>
2020
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="SwitchTableViewCell" id="vah-ss-3Ud" customClass="SwitchTableViewCell" customModule="Loop" customModuleProvider="target">
21-
<rect key="frame" x="0.0" y="119.5" width="320" height="44"/>
21+
<rect key="frame" x="0.0" y="120" width="320" height="44"/>
2222
<autoresizingMask key="autoresizingMask"/>
2323
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="vah-ss-3Ud" id="D0A-EB-kmz">
2424
<frame key="frameInset" width="320" height="43"/>
@@ -46,21 +46,21 @@
4646
</connections>
4747
</tableViewCell>
4848
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="ConfigTableViewCell" textLabel="5TX-kX-nBo" detailTextLabel="m9c-SQ-djE" style="IBUITableViewCellStyleValue1" id="0EG-OG-YuT">
49-
<rect key="frame" x="0.0" y="163.5" width="320" height="44"/>
49+
<rect key="frame" x="0.0" y="164" width="320" height="44"/>
5050
<autoresizingMask key="autoresizingMask"/>
5151
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="0EG-OG-YuT" id="af2-sZ-CY0">
52-
<frame key="frameInset" width="287" height="43.5"/>
52+
<frame key="frameInset" width="287" height="43"/>
5353
<autoresizingMask key="autoresizingMask"/>
5454
<subviews>
5555
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Pump ID" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="5TX-kX-nBo">
56-
<frame key="frameInset" minX="15" minY="12" width="65" height="20.5"/>
56+
<frame key="frameInset" minX="15" minY="11" width="65" height="21"/>
5757
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
5858
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
5959
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
6060
<nil key="highlightedColor"/>
6161
</label>
6262
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Tap to set" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="m9c-SQ-djE">
63-
<frame key="frameInset" minX="209" minY="12" width="76" height="20.5"/>
63+
<frame key="frameInset" minX="209" minY="11" width="76" height="21"/>
6464
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
6565
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
6666
<color key="textColor" red="0.55676333109537768" green="0.55676333109537768" blue="0.55676333109537768" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
@@ -123,7 +123,7 @@
123123
<rect key="frame" x="0.0" y="92" width="320" height="270"/>
124124
<autoresizingMask key="autoresizingMask"/>
125125
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mQk-9D-0ub" id="B1i-Pw-wSw">
126-
<frame key="frameInset" width="320" height="269.5"/>
126+
<frame key="frameInset" width="320" height="269"/>
127127
<autoresizingMask key="autoresizingMask"/>
128128
<subviews>
129129
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FBL-RL-faM" customClass="ChartContentView" customModule="Loop" customModuleProvider="target">
@@ -165,7 +165,7 @@
165165
<rect key="frame" x="0.0" y="362" width="320" height="64"/>
166166
<autoresizingMask key="autoresizingMask"/>
167167
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Xc2-a9-ojZ" id="a4h-tq-Rnl">
168-
<frame key="frameInset" width="320" height="63.5"/>
168+
<frame key="frameInset" width="320" height="63"/>
169169
<autoresizingMask key="autoresizingMask"/>
170170
<subviews>
171171
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" verticalCompressionResistancePriority="751" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bIL-Ub-qYp">
@@ -197,7 +197,7 @@
197197
<rect key="frame" x="0.0" y="426" width="320" height="64"/>
198198
<autoresizingMask key="autoresizingMask"/>
199199
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="I71-cY-0y7" id="0f9-ja-YFt">
200-
<frame key="frameInset" width="320" height="63.5"/>
200+
<frame key="frameInset" width="320" height="63"/>
201201
<autoresizingMask key="autoresizingMask"/>
202202
<subviews>
203203
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="249" verticalHuggingPriority="252" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zbc-87-wxZ">
@@ -662,7 +662,7 @@
662662
<rect key="frame" x="0.0" y="99" width="320" height="44"/>
663663
<autoresizingMask key="autoresizingMask"/>
664664
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="DoN-m5-O7j" id="3OB-7U-Jvb">
665-
<frame key="frameInset" width="320" height="43.5"/>
665+
<frame key="frameInset" width="320" height="43"/>
666666
<autoresizingMask key="autoresizingMask"/>
667667
<subviews>
668668
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Recommended" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ywT-OR-NnU">
@@ -704,7 +704,7 @@
704704
<rect key="frame" x="0.0" y="143" width="320" height="44"/>
705705
<autoresizingMask key="autoresizingMask"/>
706706
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="us0-UE-Wqz" id="2fI-OE-GLU">
707-
<frame key="frameInset" width="320" height="43.5"/>
707+
<frame key="frameInset" width="320" height="43"/>
708708
<autoresizingMask key="autoresizingMask"/>
709709
<subviews>
710710
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Bolus" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5oA-6d-ZTL">
@@ -745,7 +745,7 @@
745745
<rect key="frame" x="0.0" y="187" width="320" height="44"/>
746746
<autoresizingMask key="autoresizingMask"/>
747747
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="efV-tT-gC9" id="nq8-dv-ceA">
748-
<frame key="frameInset" width="320" height="43.5"/>
748+
<frame key="frameInset" width="320" height="43"/>
749749
<autoresizingMask key="autoresizingMask"/>
750750
<subviews>
751751
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ya0-9b-ZAS">

Loop/Models/Glucose.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ extension Glucose: SensorDisplayable {
5151
return .upUpUp
5252
}
5353
}
54+
55+
var isLocal: Bool {
56+
return true
57+
}
5458
}

Loop/Models/GlucoseG4.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ extension GlucoseG4: SensorDisplayable {
3939
var trendType: GlucoseTrend? {
4040
return GlucoseTrend(rawValue: Int(trend))
4141
}
42+
43+
var isLocal: Bool {
44+
return true
45+
}
4246
}

Loop/Models/MySentryPumpStatusMessageBody.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ extension MySentryPumpStatusMessageBody: SensorDisplayable {
3838
return .flat
3939
}
4040
}
41+
42+
var isLocal: Bool {
43+
return true
44+
}
4145
}

Loop/Models/SensorDisplayable.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ protocol SensorDisplayable {
1818

1919
/// Enumerates the trend of the sensor values
2020
var trendType: GlucoseTrend? { get }
21+
22+
/// Returns wheter the data is from a locally-connected device
23+
var isLocal: Bool { get }
2124
}
2225

2326

Loop/Models/ShareGlucose+GlucoseKit.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ extension ShareGlucose: SensorDisplayable {
3131
var trendType: GlucoseTrend? {
3232
return GlucoseTrend(rawValue: Int(trend))
3333
}
34+
35+
var isLocal: Bool {
36+
return false
37+
}
3438
}

Loop/View Controllers/PredictionTableViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass, U
300300
if let eventualGlucose = eventualGlucoseDescription {
301301
cell.titleLabel?.text = String(format: NSLocalizedString("Eventually %@", comment: "The subtitle format describing eventual glucose. (1: localized glucose value description)"), eventualGlucose)
302302
} else {
303-
cell.titleLabel?.text = nil
303+
cell.titleLabel?.text = ""
304304
}
305305
default:
306306
break
@@ -321,7 +321,7 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass, U
321321
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
322322
switch Section(rawValue: indexPath.section)! {
323323
case .charts:
324-
return 270
324+
return 275
325325
case .inputs, .settings:
326326
return 60
327327
}

Loop/Views/GlucoseHUDView.swift

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@ final class GlucoseHUDView: HUDView {
3737
}
3838
}
3939

40+
private enum SensorAlertState {
41+
case ok
42+
case missing
43+
case invalid
44+
case remote
45+
}
46+
47+
private var sensorAlertState = SensorAlertState.ok {
48+
didSet {
49+
var alertLabelAlpha: CGFloat = 1
50+
51+
switch sensorAlertState {
52+
case .ok:
53+
alertLabelAlpha = 0
54+
case .missing, .invalid:
55+
alertLabel.backgroundColor = UIColor.agingColor
56+
alertLabel.text = "!"
57+
case .remote:
58+
alertLabel.backgroundColor = UIColor.unknownColor
59+
alertLabel.text = "☁︎"
60+
}
61+
62+
UIView.animate(withDuration: 0.25, animations: {
63+
self.alertLabel.alpha = alertLabelAlpha
64+
})
65+
}
66+
}
67+
4068
func set(_ glucoseValue: GlucoseValue, for unit: HKUnit, from sensor: SensorDisplayable?) {
4169
var accessibilityStrings = [String]()
4270

@@ -56,16 +84,19 @@ final class GlucoseHUDView: HUDView {
5684
accessibilityStrings.append(trend.localizedDescription)
5785
}
5886

59-
if sensor?.isStateValid == false {
87+
if sensor == nil {
88+
sensorAlertState = .missing
89+
} else if sensor!.isStateValid == false {
90+
sensorAlertState = .invalid
6091
accessibilityStrings.append(NSLocalizedString("Needs attention", comment: "Accessibility label component for glucose HUD describing an invalid state"))
92+
} else if sensor!.isLocal == false {
93+
sensorAlertState = .remote
94+
} else {
95+
sensorAlertState = .ok
6196
}
6297

6398
unitLabel.text = unitStrings.joined(separator: " ")
6499
accessibilityValue = accessibilityStrings.joined(separator: ", ")
65-
66-
UIView.animate(withDuration: 0.25, animations: {
67-
self.alertLabel.alpha = sensor?.isStateValid == true ? 0 : 1
68-
})
69100
}
70101

71102
private lazy var timeFormatter: DateFormatter = {

0 commit comments

Comments
 (0)