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
Rethink the API for clients to read loop status; other cleanup.
- Refactors common behavior between chart view controllers into a superclass
- Renames "dataManager" to "deviceManager" in a few places
- Improves touch tracking in charts
- Fixes an issue where the Y-axis line was visible
- Reduces excess padding on the right side of charts
  • Loading branch information
ps2 committed May 13, 2017
commit a93487b4fa4d5b95578196ad30304ae08622731e
8 changes: 8 additions & 0 deletions Common/Extensions/NSTimeInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import Foundation


extension TimeInterval {
static func minutes(_ minutes: Double) -> TimeInterval {
return TimeInterval(minutes: minutes)
}

static func hours(_ hours: Double) -> TimeInterval {
return TimeInterval(hours: hours)
}

init(minutes: Double) {
self.init(minutes * 60)
}
Expand Down
17 changes: 11 additions & 6 deletions Common/Extensions/NumberFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,26 @@ extension NumberFormatter {
return numberFormatter
}

func describingGlucose(_ value: Double, for unit: HKUnit) -> String? {
guard let stringValue = string(from: NSNumber(value: value)) else {
func string(from number: Double, unit: String) -> String? {
guard let stringValue = string(from: NSNumber(value: number)) else {
return nil
}

return String(
format: NSLocalizedString("GLUCOSE_VALUE_AND_UNIT",
value: "%1$@ %2$@",
comment: "Format string for combining localized glucose value and unit. (1: glucose value)(2: unit)"
format: NSLocalizedString(
"QUANTITY_VALUE_AND_UNIT",
value: "%1$@ %2$@",
comment: "Format string for combining localized numeric value and unit. (1: numeric value)(2: unit)"
),
stringValue,
unit.glucoseUnitDisplayString
unit
)
}

func describingGlucose(_ value: Double, for unit: HKUnit) -> String? {
return string(from: value, unit: unit.glucoseUnitDisplayString)
}

@nonobjc func describingGlucose(_ value: HKQuantity, for unit: HKUnit) -> String? {
return describingGlucose(value.doubleValue(for: unit), for: unit)
}
Expand Down
4 changes: 4 additions & 0 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
439BED2A1E76093C00B0AED5 /* CGMManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439BED291E76093C00B0AED5 /* CGMManager.swift */; };
439BED2C1E760A7A00B0AED5 /* DexCGMManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439BED2B1E760A7A00B0AED5 /* DexCGMManager.swift */; };
439BED2E1E760BC600B0AED5 /* EnliteCGMManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439BED2D1E760BC600B0AED5 /* EnliteCGMManager.swift */; };
43A51E211EB6DBDD000736CC /* ChartsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A51E201EB6DBDD000736CC /* ChartsTableViewController.swift */; };
43A567691C94880B00334FAC /* LoopDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A567681C94880B00334FAC /* LoopDataManager.swift */; };
43A5676B1C96155700334FAC /* SwitchTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A5676A1C96155700334FAC /* SwitchTableViewCell.swift */; };
43A943761B926B7B0051FA24 /* Interface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 43A943741B926B7B0051FA24 /* Interface.storyboard */; };
Expand Down Expand Up @@ -429,6 +430,7 @@
439BED291E76093C00B0AED5 /* CGMManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGMManager.swift; sourceTree = "<group>"; };
439BED2B1E760A7A00B0AED5 /* DexCGMManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DexCGMManager.swift; sourceTree = "<group>"; };
439BED2D1E760BC600B0AED5 /* EnliteCGMManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnliteCGMManager.swift; sourceTree = "<group>"; };
43A51E201EB6DBDD000736CC /* ChartsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartsTableViewController.swift; sourceTree = "<group>"; };
43A567681C94880B00334FAC /* LoopDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = LoopDataManager.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
43A5676A1C96155700334FAC /* SwitchTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwitchTableViewCell.swift; sourceTree = "<group>"; };
43A943721B926B7B0051FA24 /* WatchApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WatchApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -853,6 +855,7 @@
43DBF04B1C93B8D700B3C386 /* BolusViewController.swift */,
4315D2861CA5CC3B00589052 /* CarbEntryEditTableViewController.swift */,
43DBF0581C93F73800B3C386 /* CarbEntryTableViewController.swift */,
43A51E201EB6DBDD000736CC /* ChartsTableViewController.swift */,
433EA4C31D9F71C800CD78FB /* CommandResponseViewController.swift */,
C178249F1E19CF9800D9D25C /* GlucoseThresholdTableViewController.swift */,
4302F4E21D4EA54200F0FCAF /* InsulinDeliveryTableViewController.swift */,
Expand Down Expand Up @@ -1508,6 +1511,7 @@
4F70C2101DE8FAC5006380B7 /* StatusExtensionDataManager.swift in Sources */,
436FACEE1D0BA636004E2427 /* InsulinDataSource.swift in Sources */,
439897371CD2F80600223065 /* AnalyticsManager.swift in Sources */,
43A51E211EB6DBDD000736CC /* ChartsTableViewController.swift in Sources */,
4346D1F61C78501000ABAFE3 /* ChartPoint+Loop.swift in Sources */,
438849EE1D2A1EBB003B3F23 /* MLabService.swift in Sources */,
43D848B21E7DF42500DADCBC /* LoopSettings.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Loop/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {

if let navVC = window?.rootViewController as? UINavigationController,
let statusVC = navVC.viewControllers.first as? StatusTableViewController {
statusVC.dataManager = deviceManager
statusVC.deviceManager = deviceManager
}

return true
Expand Down
75 changes: 38 additions & 37 deletions Loop/Extensions/NSUserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,45 @@ import HealthKit
extension UserDefaults {

private enum Key: String {
case BasalRateSchedule = "com.loudnate.Naterade.BasalRateSchedule"
case basalRateSchedule = "com.loudnate.Naterade.BasalRateSchedule"
case batteryChemistry = "com.loopkit.Loop.BatteryChemistry"
case cgmSettings = "com.loopkit.Loop.cgmSettings"
case CarbRatioSchedule = "com.loudnate.Naterade.CarbRatioSchedule"
case ConnectedPeripheralIDs = "com.loudnate.Naterade.ConnectedPeripheralIDs"
case carbRatioSchedule = "com.loudnate.Naterade.CarbRatioSchedule"
case connectedPeripheralIDs = "com.loudnate.Naterade.ConnectedPeripheralIDs"
case loopSettings = "com.loopkit.Loop.loopSettings"
case InsulinActionDuration = "com.loudnate.Naterade.InsulinActionDuration"
case InsulinSensitivitySchedule = "com.loudnate.Naterade.InsulinSensitivitySchedule"
case PreferredInsulinDataSource = "com.loudnate.Loop.PreferredInsulinDataSource"
case PumpID = "com.loudnate.Naterade.PumpID"
case PumpModelNumber = "com.loudnate.Naterade.PumpModelNumber"
case PumpRegion = "com.loopkit.Loop.PumpRegion"
case PumpTimeZone = "com.loudnate.Naterade.PumpTimeZone"
case BatteryChemistry = "com.loopkit.Loop.BatteryChemistry"
case insulinActionDuration = "com.loudnate.Naterade.InsulinActionDuration"
case insulinCounteractionEffects = "com.loopkit.Loop.insulinCounteractionEffects"
case insulinSensitivitySchedule = "com.loudnate.Naterade.InsulinSensitivitySchedule"
case preferredInsulinDataSource = "com.loudnate.Loop.PreferredInsulinDataSource"
case pumpID = "com.loudnate.Naterade.PumpID"
case pumpModelNumber = "com.loudnate.Naterade.PumpModelNumber"
case pumpRegion = "com.loopkit.Loop.PumpRegion"
case pumpTimeZone = "com.loudnate.Naterade.PumpTimeZone"
}

var basalRateSchedule: BasalRateSchedule? {
get {
if let rawValue = dictionary(forKey: Key.BasalRateSchedule.rawValue) {
if let rawValue = dictionary(forKey: Key.basalRateSchedule.rawValue) {
return BasalRateSchedule(rawValue: rawValue)
} else {
return nil
}
}
set {
set(newValue?.rawValue, forKey: Key.BasalRateSchedule.rawValue)
set(newValue?.rawValue, forKey: Key.basalRateSchedule.rawValue)
}
}

var carbRatioSchedule: CarbRatioSchedule? {
get {
if let rawValue = dictionary(forKey: Key.CarbRatioSchedule.rawValue) {
if let rawValue = dictionary(forKey: Key.carbRatioSchedule.rawValue) {
return CarbRatioSchedule(rawValue: rawValue)
} else {
return nil
}
}
set {
set(newValue?.rawValue, forKey: Key.CarbRatioSchedule.rawValue)
set(newValue?.rawValue, forKey: Key.carbRatioSchedule.rawValue)
}
}

Expand Down Expand Up @@ -93,10 +94,10 @@ extension UserDefaults {

var connectedPeripheralIDs: [String] {
get {
return array(forKey: Key.ConnectedPeripheralIDs.rawValue) as? [String] ?? []
return array(forKey: Key.connectedPeripheralIDs.rawValue) as? [String] ?? []
}
set {
set(newValue, forKey: Key.ConnectedPeripheralIDs.rawValue)
set(newValue, forKey: Key.connectedPeripheralIDs.rawValue)
}
}

Expand Down Expand Up @@ -159,98 +160,98 @@ extension UserDefaults {

var insulinActionDuration: TimeInterval? {
get {
let value = double(forKey: Key.InsulinActionDuration.rawValue)
let value = double(forKey: Key.insulinActionDuration.rawValue)

return value > 0 ? value : nil
}
set {
if let insulinActionDuration = newValue {
set(insulinActionDuration, forKey: Key.InsulinActionDuration.rawValue)
set(insulinActionDuration, forKey: Key.insulinActionDuration.rawValue)
} else {
removeObject(forKey: Key.InsulinActionDuration.rawValue)
removeObject(forKey: Key.insulinActionDuration.rawValue)
}
}
}

var insulinSensitivitySchedule: InsulinSensitivitySchedule? {
get {
if let rawValue = dictionary(forKey: Key.InsulinSensitivitySchedule.rawValue) {
if let rawValue = dictionary(forKey: Key.insulinSensitivitySchedule.rawValue) {
return InsulinSensitivitySchedule(rawValue: rawValue)
} else {
return nil
}
}
set {
set(newValue?.rawValue, forKey: Key.InsulinSensitivitySchedule.rawValue)
set(newValue?.rawValue, forKey: Key.insulinSensitivitySchedule.rawValue)
}
}

var preferredInsulinDataSource: InsulinDataSource? {
get {
return InsulinDataSource(rawValue: integer(forKey: Key.PreferredInsulinDataSource.rawValue))
return InsulinDataSource(rawValue: integer(forKey: Key.preferredInsulinDataSource.rawValue))
}
set {
if let preferredInsulinDataSource = newValue {
set(preferredInsulinDataSource.rawValue, forKey: Key.PreferredInsulinDataSource.rawValue)
set(preferredInsulinDataSource.rawValue, forKey: Key.preferredInsulinDataSource.rawValue)
} else {
removeObject(forKey: Key.PreferredInsulinDataSource.rawValue)
removeObject(forKey: Key.preferredInsulinDataSource.rawValue)
}
}
}

var pumpID: String? {
get {
return string(forKey: Key.PumpID.rawValue)
return string(forKey: Key.pumpID.rawValue)
}
set {
set(newValue, forKey: Key.PumpID.rawValue)
set(newValue, forKey: Key.pumpID.rawValue)
}
}

var pumpModelNumber: String? {
get {
return string(forKey: Key.PumpModelNumber.rawValue)
return string(forKey: Key.pumpModelNumber.rawValue)
}
set {
set(newValue, forKey: Key.PumpModelNumber.rawValue)
set(newValue, forKey: Key.pumpModelNumber.rawValue)
}
}

var pumpRegion: PumpRegion? {
get {
// Defaults to 0 / northAmerica
return PumpRegion(rawValue: integer(forKey: Key.PumpRegion.rawValue))
return PumpRegion(rawValue: integer(forKey: Key.pumpRegion.rawValue))
}
set {
set(newValue?.rawValue, forKey: Key.PumpRegion.rawValue)
set(newValue?.rawValue, forKey: Key.pumpRegion.rawValue)
}
}

var pumpTimeZone: TimeZone? {
get {
if let offset = object(forKey: Key.PumpTimeZone.rawValue) as? NSNumber {
if let offset = object(forKey: Key.pumpTimeZone.rawValue) as? NSNumber {
return TimeZone(secondsFromGMT: offset.intValue)
} else {
return nil
}
} set {
if let value = newValue {
set(NSNumber(value: value.secondsFromGMT() as Int), forKey: Key.PumpTimeZone.rawValue)
set(NSNumber(value: value.secondsFromGMT() as Int), forKey: Key.pumpTimeZone.rawValue)
} else {
removeObject(forKey: Key.PumpTimeZone.rawValue)
removeObject(forKey: Key.pumpTimeZone.rawValue)
}
}
}

var batteryChemistry: BatteryChemistryType? {
get {
return BatteryChemistryType(rawValue: integer(forKey: Key.BatteryChemistry.rawValue))
return BatteryChemistryType(rawValue: integer(forKey: Key.batteryChemistry.rawValue))
}
set {
if let batteryChemistry = newValue {
set(batteryChemistry.rawValue, forKey: Key.BatteryChemistry.rawValue)
set(batteryChemistry.rawValue, forKey: Key.batteryChemistry.rawValue)
} else {
removeObject(forKey: Key.BatteryChemistry.rawValue)
removeObject(forKey: Key.batteryChemistry.rawValue)
}
}
}
Expand Down
Loading