Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Loop/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ 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

NotificationManager.authorize()

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
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 6 additions & 5 deletions Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -619,6 +621,7 @@ final class DeviceDataManager: CarbStoreDelegate, DoseStoreDelegate, Transmitter

self.pumpState = pumpState
} else {
pumpID = nil
self.pumpState = nil
}

Expand Down Expand Up @@ -868,8 +871,6 @@ final class DeviceDataManager: CarbStoreDelegate, DoseStoreDelegate, Transmitter

// MARK: - Initialization

static let sharedManager = DeviceDataManager()

private(set) var loopManager: LoopDataManager!

init() {
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions Loop/View Controllers/SettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion Loop/View Controllers/StatusTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down