Skip to content

Commit 80cdb25

Browse files
Bharat Medirattaps2
authored andcommitted
Swift 3.1 - post widget merge cleanups (#424)
* Extend ChartColorPalette in Loop target to add a .default() palette * Update chart appropriately when we remove glucose targets * Drop the first predicted glucose entry. It's the current glucose and its interval to the second is not uniform with the interval for the rest * Use predictedGlucose.startIndex for clarity instead of hardcoding indexes
1 parent 9e57e95 commit 80cdb25

19 files changed

+241
-149
lines changed

Loop Status Extension/DatedRangedContextCalculator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import Foundation
1010
import SwiftCharts
1111

12+
import LoopUI
13+
1214
class DatedRangeContextCalculator: TargetPointsCalculator {
1315

1416
var targetRanges: [DatedRangeContext]?

Loop Status Extension/StatusViewController.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class StatusViewController: UIViewController, NCWidgetProviding {
2929
@IBOutlet weak var glucoseChartContentView: ChartContentView!
3030

3131
private lazy var charts: StatusChartsManager = {
32-
let charts = StatusChartsManager()
32+
let charts = StatusChartsManager(colors: ChartColorPalette(axisLine: .axisLineColor, axisLabel: .axisLabelColor, grid: .gridColor, glucoseTint: .glucoseTintColor, doseTint: .doseTintColor))
3333

3434
charts.glucoseDisplayRange = (
3535
min: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 100),
@@ -227,10 +227,7 @@ class StatusViewController: UIViewController, NCWidgetProviding {
227227
)
228228
subtitleLabel.alpha = 1
229229
}
230-
231-
charts.endDate = eventualGlucose.startDate
232230
}
233-
234231
}
235232

236233
charts.targetPointsCalculator = DatedRangeContextCalculator(targetRanges: context.targetRanges, temporaryOverride: context.temporaryOverride)

Loop Status Extension/UIColor+Widget.swift

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

99
import UIKit
10+
import LoopUI
1011

1112
extension UIColor {
1213
@nonobjc static let axisLabelColor = subtitleLabelColor

Loop.xcodeproj/project.pbxproj

Lines changed: 66 additions & 44 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// ChartColorPalette+Loop.swift
3+
// Loop
4+
//
5+
// Created by Bharat Mediratta on 4/1/17.
6+
// Copyright © 2017 LoopKit Authors. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
import LoopUI
12+
13+
extension ChartColorPalette {
14+
static var `default`: ChartColorPalette {
15+
get {
16+
return ChartColorPalette(axisLine: .axisLineColor, axisLabel: .axisLabelColor, grid: .gridColor, glucoseTint: .glucoseTintColor, doseTint: .doseTintColor)
17+
}
18+
}
19+
}

Loop/Extensions/UIColor+Loop.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// Copyright © 2016 LoopKit Authors. All rights reserved.
77
//
88

9-
109
import UIKit
10+
import LoopUI
1111

1212
extension UIColor {
1313
@nonobjc static let axisLabelColor = secondaryLabelColor

Loop/Managers/GlucoseRangeScheduleCalculator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Foundation
1010
import LoopKit
1111
import SwiftCharts
12+
import LoopUI
1213

1314
class GlucoseRangeScheduleCalculator: TargetPointsCalculator {
1415

Loop/Managers/StatusChartsManager+LoopKit.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import GlucoseKit
1313
import InsulinKit
1414
import LoopKit
1515
import SwiftCharts
16+
import LoopUI
1617

1718
extension StatusChartsManager {
1819

Loop/Managers/StatusExtensionDataManager.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,19 @@ final class StatusExtensionDataManager {
101101
startDate: $0.startDate
102102
)
103103
})
104-
104+
105105
// Only tranfer the predicted glucose if we have glucose history
106-
if let predictedGlucose = predictedGlucose,
106+
// Drop the first element in predictedGlucose because it is the currentGlucose
107+
// and will have a different interval to the next element
108+
if let predictedGlucose = predictedGlucose?.dropFirst(),
107109
predictedGlucose.count > 1 {
110+
let first = predictedGlucose[predictedGlucose.startIndex]
111+
let second = predictedGlucose[predictedGlucose.startIndex.advanced(by: 1)]
108112
context.predictedGlucose = PredictedGlucoseContext(
109113
values: predictedGlucose.map { $0.quantity.doubleValue(for: glucoseUnit) },
110114
unit: glucoseUnit,
111-
startDate: predictedGlucose[0].startDate,
112-
interval: predictedGlucose[1].startDate.timeIntervalSince(predictedGlucose[0].startDate))
115+
startDate: first.startDate,
116+
interval: second.startDate.timeIntervalSince(first.startDate))
113117
}
114118
updateGroup.leave()
115119
}

Loop/View Controllers/PredictionTableViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import UIKit
1010
import HealthKit
1111
import LoopKit
12+
import LoopUI
1213

1314

1415
class PredictionTableViewController: UITableViewController, IdentifiableClass, UIGestureRecognizerDelegate {
@@ -88,7 +89,7 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass, U
8889
var dataManager: DeviceDataManager!
8990

9091
private lazy var charts: StatusChartsManager = {
91-
let charts = StatusChartsManager()
92+
let charts = StatusChartsManager(colors: .default)
9293

9394
charts.glucoseDisplayRange = (
9495
min: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 60),

0 commit comments

Comments
 (0)