Skip to content

Commit 8de3796

Browse files
authored
Pumpmanager changes (#877)
* Omnikit * Add OmniKit frameworks * fix cartfile * Track lastAddedPumpData, including lastAddedPumpEvents * Fix carthage copy frameworks script * rebase * update deps * Initialize setupViewController with existing pump settings * Suspend/Resume * Use normal separator behavior * Reload pump section after adding pumpmanager * LoopKit PumpManagerStatus updates * PumpManagerUI vended HUD views * Add missing file * Update to LoopKit naming changes * Push instead of present pumpmanager vended vc in response to HUD view tap * Add prep_workspace.sh script * HUDProvider updates * Fix hud clearing after removing pump manager. Show boluses that take > 5 minutes * PumpManager returns DoseEntry for requested bolus, including duration * Example jumpstart * Suspend/Resume with new PumpManager status updates * Fix issue with DeviceDataManager missing from issue report * Handle LoopKit and rileylink_ios updates * Cleanup testing code * Update Loop today widget when HUD views change * Renaming updates from LoopKit * Updates for recent LoopKit pumpmanager-changes branch * update prep script for CGMBLEKit branch change * Updates for hud provider delegate change * Pumpmanager updates * Update prep script * Fix permissions on prep workspace script * Pumpmanager changes * Update to pumpmanager-updates * Back out DEVELOPMENT_TEAM settings * Context object does not need HUDProvider reference * Include dose in enactBolus completion * Bump dependency revisions * Update HUD set of views only on PumpManager change * Remove unused file * synchronize deviceDataManager.pumpManagerStatus access * Bump dep revisions * Remove unused files * Remove unneeded reloadSections calls * Fix build issue when carthage is run from Xcode * Use bolus end date to clear lastRequestedBolus * present instead of show settings vc * small refactorings * Improvements from @mpangburn's review * Update active flag on HUDProvider when hud is visible and app is active * Remove signing team changes * HUDProvider active -> visible * Use LoopKit dev * Use constant for battery replacement detection threshold * Force git protocol 1 to fix travis builds
1 parent 574ecbc commit 8de3796

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+525
-722
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ osx_image: xcode10
44
# xcode_project: Loop.xcodeproj
55
# xcode_scheme: Loop
66
before_script:
7+
- git config --global protocol.version 1
78
- set -o pipefail && xcodebuild -project Loop.xcodeproj -target Cartfile
89
script:
910
# Build the app target

Cartfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
2-
github "LoopKit/LoopKit" == 2.2.1
3-
github "LoopKit/CGMBLEKit" == 3.0
1+
github "LoopKit/LoopKit" "dev"
2+
github "LoopKit/CGMBLEKit" "dev"
43
github "i-schuetz/SwiftCharts" == 0.6.2
5-
github "LoopKit/dexcom-share-client-swift" == 1.0
6-
github "LoopKit/G4ShareSpy" == 1.0
7-
github "ps2/rileylink_ios" == 2.1.0
4+
github "LoopKit/dexcom-share-client-swift" "dev"
5+
github "LoopKit/G4ShareSpy" "dev"
6+
github "ps2/rileylink_ios" "dev"
87
github "LoopKit/Amplitude-iOS" "decreepify"

Cartfile.resolved

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github "LoopKit/Amplitude-iOS" "2137d5fd44bf630ed33e1e72d7af6d8f8612f270"
2-
github "LoopKit/CGMBLEKit" "v3.0"
3-
github "LoopKit/G4ShareSpy" "v1.0"
4-
github "LoopKit/LoopKit" "v2.2.1"
5-
github "LoopKit/dexcom-share-client-swift" "v1.0"
2+
github "LoopKit/CGMBLEKit" "ea1267791c66e884f1013fffd36faf4555cc6eaf"
3+
github "LoopKit/G4ShareSpy" "fed5a389e3e47e3a1953878dd21852aa5f44b360"
4+
github "LoopKit/LoopKit" "bf4166bc77f89e22971f2030ad006967881ff082"
5+
github "LoopKit/dexcom-share-client-swift" "b0419edf55c7f389b36cb47dd5c376bbd3d03d69"
66
github "i-schuetz/SwiftCharts" "0.6.2"
7-
github "ps2/rileylink_ios" "v2.1.0"
7+
github "ps2/rileylink_ios" "46ed2c845e7c4b88c721994d8e8432e86be4c699"
File renamed without changes.

Common/Models/PumpManagerUI.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// PumpManagerUI.swift
3+
// Loop
4+
//
5+
// Created by Pete Schwamb on 10/18/18.
6+
// Copyright © 2018 LoopKit Authors. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import LoopKit
11+
import LoopKitUI
12+
import MinimedKit
13+
import MinimedKitUI
14+
15+
private let managersByIdentifier: [String: PumpManagerUI.Type] = allPumpManagers.compactMap{ $0 as? PumpManagerUI.Type}.reduce(into: [:]) { (map, Type) in
16+
map[Type.managerIdentifier] = Type
17+
}
18+
19+
typealias PumpManagerHUDViewsRawValue = [String: Any]
20+
21+
func PumpManagerHUDViewsFromRawValue(_ rawValue: PumpManagerHUDViewsRawValue) -> [BaseHUDView]? {
22+
guard let rawState = rawValue["hudProviderViews"] as? HUDProvider.HUDViewsRawState,
23+
let managerIdentifier = rawValue["managerIdentifier"] as? String,
24+
let manager = managersByIdentifier[managerIdentifier]
25+
else {
26+
return nil
27+
}
28+
29+
return manager.createHUDViews(rawValue: rawState)
30+
}
31+
32+
func PumpManagerHUDViewsRawValueFromHudProvider(_ hudProvider: HUDProvider) -> PumpManagerHUDViewsRawValue {
33+
return [
34+
"managerIdentifier": hudProvider.managerIdentifier,
35+
"hudProviderViews": hudProvider.hudViewsRawState
36+
]
37+
}

Common/Models/StatusExtensionContext.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import Foundation
1111
import HealthKit
1212
import LoopKit
13+
import LoopKitUI
1314

1415

1516
struct NetBasalContext {
@@ -151,6 +152,32 @@ extension PredictedGlucoseContext: RawRepresentable {
151152
}
152153
}
153154

155+
struct PumpManagerHUDViewsContext: RawRepresentable {
156+
typealias RawValue = [String: Any]
157+
158+
let pumpManagerHUDViewsRawValue: PumpManagerHUDViewsRawValue
159+
160+
var hudViews: [BaseHUDView]? {
161+
return PumpManagerHUDViewsFromRawValue(pumpManagerHUDViewsRawValue)
162+
}
163+
164+
init(pumpManagerHUDViewsRawValue: PumpManagerHUDViewsRawValue) {
165+
self.pumpManagerHUDViewsRawValue = pumpManagerHUDViewsRawValue
166+
}
167+
168+
init?(rawValue: RawValue) {
169+
if let pumpManagerHUDViewsRawValue = rawValue["pumpManagerHUDViewsRawValue"] as? PumpManagerHUDViewsRawValue {
170+
self.pumpManagerHUDViewsRawValue = pumpManagerHUDViewsRawValue
171+
} else {
172+
return nil
173+
}
174+
}
175+
176+
var rawValue: RawValue {
177+
return ["pumpManagerHUDViewsRawValue": pumpManagerHUDViewsRawValue]
178+
}
179+
}
180+
154181
struct StatusExtensionContext: RawRepresentable {
155182
typealias RawValue = [String: Any]
156183
private let version = 5
@@ -161,6 +188,7 @@ struct StatusExtensionContext: RawRepresentable {
161188
var batteryPercentage: Double?
162189
var reservoirCapacity: Double?
163190
var sensor: SensorDisplayableContext?
191+
var pumpManagerHUDViewsContext: PumpManagerHUDViewsContext?
164192

165193
init() { }
166194

@@ -184,6 +212,10 @@ struct StatusExtensionContext: RawRepresentable {
184212
if let rawValue = rawValue["sensor"] as? SensorDisplayableContext.RawValue {
185213
sensor = SensorDisplayableContext(rawValue: rawValue)
186214
}
215+
216+
if let rawPumpManagerHUDViewsContext = rawValue["pumpManagerHUDViewsContext"] as? PumpManagerHUDViewsContext.RawValue {
217+
pumpManagerHUDViewsContext = PumpManagerHUDViewsContext(rawValue: rawPumpManagerHUDViewsContext)
218+
}
187219
}
188220

189221
var rawValue: RawValue {
@@ -197,6 +229,8 @@ struct StatusExtensionContext: RawRepresentable {
197229
raw["batteryPercentage"] = batteryPercentage
198230
raw["reservoirCapacity"] = reservoirCapacity
199231
raw["sensor"] = sensor?.rawValue
232+
raw["pumpManagerHUDViewsContext"] = pumpManagerHUDViewsContext?.rawValue
233+
200234
return raw
201235
}
202236
}

Loop Status Extension/StateColorPalette.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import LoopUI
9+
import LoopKitUI
910

1011
extension StateColorPalette {
1112
static let loopStatus = StateColorPalette(unknown: .unknownColor, normal: .freshColor, warning: .agingColor, error: .staleColor)

Loop Status Extension/StatusViewController.swift

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import CoreData
1010
import HealthKit
1111
import LoopKit
12+
import LoopKitUI
1213
import LoopUI
1314
import NotificationCenter
1415
import UIKit
@@ -22,8 +23,6 @@ class StatusViewController: UIViewController, NCWidgetProviding {
2223
hudView.glucoseHUD.stateColors = .cgmStatus
2324
hudView.glucoseHUD.tintColor = .glucoseTintColor
2425
hudView.basalRateHUD.tintColor = .doseTintColor
25-
hudView.reservoirVolumeHUD.stateColors = .pumpStatus
26-
hudView.batteryHUD.stateColors = .pumpStatus
2726
}
2827
}
2928
@IBOutlet weak var subtitleLabel: UILabel!
@@ -159,7 +158,6 @@ class StatusViewController: UIViewController, NCWidgetProviding {
159158
let group = DispatchGroup()
160159

161160
var activeInsulin: Double?
162-
var lastReservoirValue: ReservoirValue?
163161
var glucose: [StoredGlucoseSample] = []
164162

165163
group.enter()
@@ -173,17 +171,6 @@ class StatusViewController: UIViewController, NCWidgetProviding {
173171
group.leave()
174172
}
175173

176-
group.enter()
177-
doseStore.getReservoirValues(since: .distantPast, limit: 1) { (result) in
178-
switch result {
179-
case .success(let values):
180-
lastReservoirValue = values.first
181-
case .failure:
182-
lastReservoirValue = nil
183-
}
184-
group.leave()
185-
}
186-
187174
charts.startDate = Calendar.current.nextDate(after: Date(timeIntervalSinceNow: .minutes(-5)), matching: DateComponents(minute: 0), matchingPolicy: .strict, direction: .backward) ?? Date()
188175

189176
// Showing the whole history plus full prediction in the glucose plot
@@ -201,13 +188,20 @@ class StatusViewController: UIViewController, NCWidgetProviding {
201188
return
202189
}
203190

204-
if let batteryPercentage = context.batteryPercentage {
205-
self.hudView.batteryHUD.batteryLevel = Double(batteryPercentage)
191+
let hudViews: [BaseHUDView]
192+
193+
if let hudViewsContext = context.pumpManagerHUDViewsContext,
194+
let contextHUDViews = hudViewsContext.hudViews
195+
{
196+
hudViews = contextHUDViews
197+
} else {
198+
hudViews = [ReservoirVolumeHUDView.instantiate(), BatteryLevelHUDView.instantiate()]
206199
}
207200

208-
if let reservoir = lastReservoirValue, let capacity = context.reservoirCapacity {
209-
self.hudView.reservoirVolumeHUD.reservoirLevel = min(1, max(0, Double(reservoir.unitVolume / capacity)))
210-
self.hudView.reservoirVolumeHUD.setReservoirVolume(volume: reservoir.unitVolume, at: reservoir.startDate)
201+
self.hudView.removePumpManagerProvidedViews()
202+
for view in hudViews {
203+
view.stateColors = .pumpStatus
204+
self.hudView.addHUDView(view)
211205
}
212206

213207
if let netBasal = context.netBasal {

0 commit comments

Comments
 (0)