From c9d6ed62b9da2da5b37a5e1f7c4f10fc54913b85 Mon Sep 17 00:00:00 2001 From: Chris Hannemann Date: Tue, 20 Sep 2016 23:02:01 -0700 Subject: [PATCH 01/11] Glucose chart range (#179) Sets a maximum minimum and minimum maximum of glucose chart y-axis; prevents chart from collapsing when glucose is stable for a long duration, which causes the data to appear noisy. --- Loop/View Controllers/StatusTableViewController.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Loop/View Controllers/StatusTableViewController.swift b/Loop/View Controllers/StatusTableViewController.swift index 08be2d6e38..675dafe670 100644 --- a/Loop/View Controllers/StatusTableViewController.swift +++ b/Loop/View Controllers/StatusTableViewController.swift @@ -135,7 +135,11 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize components.minute = 0 let date = Date(timeIntervalSinceNow: -TimeInterval(hours: 6)) charts.startDate = (calendar as NSCalendar).nextDate(after: date, matching: components, options: [.matchStrictly, .searchBackwards]) ?? date - + charts.glucoseDisplayRange = ( + min: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 75), + max: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 225) + ) + let reloadGroup = DispatchGroup() var glucoseUnit: HKUnit? From 8ed752235d3e046d95008530671d97d87c6f5497 Mon Sep 17 00:00:00 2001 From: Nathan Racklyeft Date: Wed, 21 Sep 2016 20:02:46 -0700 Subject: [PATCH 02/11] Missed a few casts during Swift 3 migration (#182) --- Loop/Managers/WatchDataManager.swift | 2 +- Loop/View Controllers/PredictionTableViewController.swift | 2 +- Loop/View Controllers/StatusTableViewController.swift | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Loop/Managers/WatchDataManager.swift b/Loop/Managers/WatchDataManager.swift index 97c6f4f68f..2a144434ae 100644 --- a/Loop/Managers/WatchDataManager.swift +++ b/Loop/Managers/WatchDataManager.swift @@ -39,7 +39,7 @@ final class WatchDataManager: NSObject, WCSessionDelegate { @objc private func updateWatch(_ notification: Notification) { guard - let rawContext = (notification as NSNotification).userInfo?[LoopDataManager.LoopUpdateContextKey] as? LoopDataManager.LoopUpdateContext.RawValue, + let rawContext = notification.userInfo?[LoopDataManager.LoopUpdateContextKey] as? LoopDataManager.LoopUpdateContext.RawValue, let context = LoopDataManager.LoopUpdateContext(rawValue: rawContext), case .tempBasal = context, let session = watchSession diff --git a/Loop/View Controllers/PredictionTableViewController.swift b/Loop/View Controllers/PredictionTableViewController.swift index 1ca479ae9a..adbd546ae9 100644 --- a/Loop/View Controllers/PredictionTableViewController.swift +++ b/Loop/View Controllers/PredictionTableViewController.swift @@ -119,7 +119,7 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass { var components = DateComponents() components.minute = 0 let date = Date(timeIntervalSinceNow: -TimeInterval(hours: 1)) - charts.startDate = (calendar as NSCalendar).nextDate(after: date, matching: components, options: [.matchStrictly, .searchBackwards]) ?? date + charts.startDate = calendar.nextDate(after: date, matching: components, matchingPolicy: .strict, direction: .backward) ?? date let reloadGroup = DispatchGroup() var glucoseUnit: HKUnit? diff --git a/Loop/View Controllers/StatusTableViewController.swift b/Loop/View Controllers/StatusTableViewController.swift index 675dafe670..ee0be4ce7b 100644 --- a/Loop/View Controllers/StatusTableViewController.swift +++ b/Loop/View Controllers/StatusTableViewController.swift @@ -134,12 +134,12 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize var components = DateComponents() components.minute = 0 let date = Date(timeIntervalSinceNow: -TimeInterval(hours: 6)) - charts.startDate = (calendar as NSCalendar).nextDate(after: date, matching: components, options: [.matchStrictly, .searchBackwards]) ?? date + charts.startDate = calendar.nextDate(after: date, matching: components, matchingPolicy: .strict, direction: .backward) ?? date charts.glucoseDisplayRange = ( min: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 75), max: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 225) ) - + let reloadGroup = DispatchGroup() var glucoseUnit: HKUnit? From 78e8c0bf93e48d249906c67bba5324f0e1ea709f Mon Sep 17 00:00:00 2001 From: Nathan Racklyeft Date: Wed, 21 Sep 2016 21:24:40 -0700 Subject: [PATCH 03/11] Fixing the removal of Pump and G5 Transmitter ID (#183) Fixes #181 --- Loop/AppDelegate.swift | 11 +++++++++-- Loop/Managers/DeviceDataManager.swift | 11 ++++++----- .../SettingsTableViewController.swift | 4 +--- Loop/View Controllers/StatusTableViewController.swift | 4 +++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Loop/AppDelegate.swift b/Loop/AppDelegate.swift index 45b1404ba5..990268eb00 100644 --- a/Loop/AppDelegate.swift +++ b/Loop/AppDelegate.swift @@ -15,6 +15,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? + private(set) lazy var dataManager = DeviceDataManager() + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { window?.tintColor = UIColor.tintColor @@ -22,6 +24,11 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { AnalyticsManager.sharedManager.application(application, didFinishLaunchingWithOptions: launchOptions) + if let navVC = window?.rootViewController as? UINavigationController, + let statusVC = navVC.viewControllers.first as? StatusTableViewController { + statusVC.dataManager = dataManager + } + return true } @@ -42,7 +49,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - DeviceDataManager.sharedManager.transmitter?.resumeScanning() + dataManager.transmitter?.resumeScanning() } func applicationWillTerminate(_ application: UIApplication) { @@ -73,7 +80,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { { AnalyticsManager.sharedManager.didRetryBolus() - DeviceDataManager.sharedManager.enactBolus(units) { (error) in + dataManager.enactBolus(units) { (error) in if error != nil { NotificationManager.sendBolusFailureNotificationForAmount(units, atDate: startDate) } diff --git a/Loop/Managers/DeviceDataManager.swift b/Loop/Managers/DeviceDataManager.swift index 66911687bf..a5182582f2 100644 --- a/Loop/Managers/DeviceDataManager.swift +++ b/Loop/Managers/DeviceDataManager.swift @@ -606,11 +606,13 @@ final class DeviceDataManager: CarbStoreDelegate, DoseStoreDelegate, Transmitter return pumpState?.pumpID } set { - guard newValue?.characters.count == 6 && newValue != pumpState?.pumpID else { + guard newValue != pumpState?.pumpID else { return } - if let pumpID = newValue { + var pumpID = newValue + + if let pumpID = pumpID, pumpID.characters.count == 6 { let pumpState = PumpState(pumpID: pumpID, pumpRegion: .northAmerica) if let timeZone = self.pumpState?.timeZone { @@ -619,6 +621,7 @@ final class DeviceDataManager: CarbStoreDelegate, DoseStoreDelegate, Transmitter self.pumpState = pumpState } else { + pumpID = nil self.pumpState = nil } @@ -868,8 +871,6 @@ final class DeviceDataManager: CarbStoreDelegate, DoseStoreDelegate, Transmitter // MARK: - Initialization - static let sharedManager = DeviceDataManager() - private(set) var loopManager: LoopDataManager! init() { @@ -933,7 +934,7 @@ final class DeviceDataManager: CarbStoreDelegate, DoseStoreDelegate, Transmitter receiver?.delegate = self } - if let transmitterID = UserDefaults.standard.transmitterID { + if let transmitterID = UserDefaults.standard.transmitterID, transmitterID.characters.count == 6 { transmitter = Transmitter(ID: transmitterID, passiveModeEnabled: true) transmitter?.delegate = self } diff --git a/Loop/View Controllers/SettingsTableViewController.swift b/Loop/View Controllers/SettingsTableViewController.swift index cd29118cbd..b95f220dc0 100644 --- a/Loop/View Controllers/SettingsTableViewController.swift +++ b/Loop/View Controllers/SettingsTableViewController.swift @@ -65,9 +65,7 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu dataManagerObserver = nil } - fileprivate var dataManager: DeviceDataManager { - return DeviceDataManager.sharedManager - } + var dataManager: DeviceDataManager! private var dataManagerObserver: Any? { willSet { diff --git a/Loop/View Controllers/StatusTableViewController.swift b/Loop/View Controllers/StatusTableViewController.swift index ee0be4ce7b..1d35d177c5 100644 --- a/Loop/View Controllers/StatusTableViewController.swift +++ b/Loop/View Controllers/StatusTableViewController.swift @@ -106,7 +106,7 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize // References to registered notification center observers private var notificationObservers: [Any] = [] - unowned let dataManager = DeviceDataManager.sharedManager + weak var dataManager: DeviceDataManager! private var active = true { didSet { @@ -559,6 +559,8 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize } case let vc as PredictionTableViewController: vc.dataManager = dataManager + case let vc as SettingsTableViewController: + vc.dataManager = dataManager default: break } From cb6deb1cf6f83bda61f82b1097db6204fe65731b Mon Sep 17 00:00:00 2001 From: Nathan Racklyeft Date: Thu, 22 Sep 2016 22:03:03 -0700 Subject: [PATCH 04/11] Minor chart improvements (#184) * Display an axis line for every graph as long as there are X values * Adding graph titles. Fixes #180 Still more cleanup work to do here, though. --- Loop/Base.lproj/Main.storyboard | 48 +++++++++------- Loop/Managers/StatusChartManager.swift | 56 +++++++++++++++---- .../PredictionTableViewController.swift | 1 + .../StatusTableViewController.swift | 12 ++-- Loop/Views/ChartTableViewCell.swift | 6 +- 5 files changed, 82 insertions(+), 41 deletions(-) diff --git a/Loop/Base.lproj/Main.storyboard b/Loop/Base.lproj/Main.storyboard index f8dea28abc..12c4052272 100644 --- a/Loop/Base.lproj/Main.storyboard +++ b/Loop/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - - + + @@ -18,10 +18,10 @@ - + - + - + - + - - + + - + + - + + + + @@ -620,7 +628,7 @@ - +