From 26438c12549dfaa1d1a3e65a6eaf08d8e2e87219 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sat, 2 Sep 2017 14:26:14 -0500 Subject: [PATCH 1/2] Font scaling fixes --- .../Base.lproj/MainInterface.storyboard | 16 +- .../StatusViewController.swift | 50 +--- Loop.xcodeproj/project.pbxproj | 4 + Loop/Base.lproj/Main.storyboard | 86 +++--- .../CarbAbsorptionViewController.swift | 42 ++- .../ChartsTableViewController.swift | 71 ++++- .../InsulinModelSettingsViewController.swift | 6 +- .../PredictionTableViewController.swift | 13 +- .../SettingsTableViewController.swift | 3 + .../StatusTableViewController.swift | 253 +++++++++++------- LoopUI/HUDView.xib | 71 ++--- LoopUI/Managers/StatusChartsManager.swift | 22 +- LoopUI/Views/HUDView.swift | 4 +- LoopUI/Views/LoopCompletionHUDView.swift | 12 +- WatchApp Extension/ExtensionDelegate.swift | 15 +- 15 files changed, 403 insertions(+), 265 deletions(-) diff --git a/Loop Status Extension/Base.lproj/MainInterface.storyboard b/Loop Status Extension/Base.lproj/MainInterface.storyboard index 91b420eed3..57419b7616 100644 --- a/Loop Status Extension/Base.lproj/MainInterface.storyboard +++ b/Loop Status Extension/Base.lproj/MainInterface.storyboard @@ -24,17 +24,17 @@ - + - + - + - + - - + + @@ -75,7 +75,7 @@ - + diff --git a/Loop Status Extension/StatusViewController.swift b/Loop Status Extension/StatusViewController.swift index a5de9e7563..271b38b941 100644 --- a/Loop Status Extension/StatusViewController.swift +++ b/Loop Status Extension/StatusViewController.swift @@ -61,36 +61,6 @@ class StatusViewController: UIViewController, NCWidgetProviding { var defaults: UserDefaults? final var observationContext = 1 - var loopCompletionHUD: LoopCompletionHUDView! { - get { - return hudView.loopCompletionHUD - } - } - - var glucoseHUD: GlucoseHUDView! { - get { - return hudView.glucoseHUD - } - } - - var basalRateHUD: BasalRateHUDView! { - get { - return hudView.basalRateHUD - } - } - - var reservoirVolumeHUD: ReservoirVolumeHUDView! { - get { - return hudView.reservoirVolumeHUD - } - } - - var batteryHUD: BatteryLevelHUDView! { - get { - return hudView.batteryHUD - } - } - override func viewDidLoad() { super.viewDidLoad() subtitleLabel.isHidden = true @@ -125,11 +95,13 @@ class StatusViewController: UIViewController, NCWidgetProviding { } func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) { + let compactHeight = hudView.systemLayoutSizeFitting(maxSize).height + subtitleLabel.systemLayoutSizeFitting(maxSize).height + switch activeDisplayMode { case .compact: - preferredContentSize = maxSize + preferredContentSize = CGSize(width: maxSize.width, height: compactHeight) case .expanded: - preferredContentSize = CGSize(width: maxSize.width, height: 210) + preferredContentSize = CGSize(width: maxSize.width, height: compactHeight + 100) } } @@ -168,7 +140,7 @@ class StatusViewController: UIViewController, NCWidgetProviding { return NCUpdateResult.failed } if let lastGlucose = context.glucose?.last { - glucoseHUD.setGlucoseQuantity(lastGlucose.value, + hudView.glucoseHUD.setGlucoseQuantity(lastGlucose.value, at: lastGlucose.startDate, unit: lastGlucose.unit, sensor: context.sensor @@ -176,21 +148,21 @@ class StatusViewController: UIViewController, NCWidgetProviding { } if let batteryPercentage = context.batteryPercentage { - batteryHUD.batteryLevel = Double(batteryPercentage) + hudView.batteryHUD.batteryLevel = Double(batteryPercentage) } if let reservoir = context.reservoir { - reservoirVolumeHUD.reservoirLevel = min(1, max(0, Double(reservoir.unitVolume / Double(reservoir.capacity)))) - reservoirVolumeHUD.setReservoirVolume(volume: reservoir.unitVolume, at: reservoir.startDate) + hudView.reservoirVolumeHUD.reservoirLevel = min(1, max(0, Double(reservoir.unitVolume / Double(reservoir.capacity)))) + hudView.reservoirVolumeHUD.setReservoirVolume(volume: reservoir.unitVolume, at: reservoir.startDate) } if let netBasal = context.netBasal { - basalRateHUD.setNetBasalRate(netBasal.rate, percent: netBasal.percentage, at: netBasal.start) + hudView.basalRateHUD.setNetBasalRate(netBasal.rate, percent: netBasal.percentage, at: netBasal.start) } if let loop = context.loop { - loopCompletionHUD.dosingEnabled = loop.dosingEnabled - loopCompletionHUD.lastLoopCompleted = loop.lastCompleted + hudView.loopCompletionHUD.dosingEnabled = loop.dosingEnabled + hudView.loopCompletionHUD.lastLoopCompleted = loop.lastCompleted } subtitleLabel.isHidden = true diff --git a/Loop.xcodeproj/project.pbxproj b/Loop.xcodeproj/project.pbxproj index 0ffb40a5c3..e265ab6ef1 100644 --- a/Loop.xcodeproj/project.pbxproj +++ b/Loop.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 43076BF31DFDBC4B0012A723 /* it.lproj in Resources */ = {isa = PBXBuildFile; fileRef = 43076BF21DFDBC4B0012A723 /* it.lproj */; }; 4309786C1E73D2F500BEBC82 /* it.lproj in Resources */ = {isa = PBXBuildFile; fileRef = 4309786B1E73D2F500BEBC82 /* it.lproj */; }; 4309786E1E73DAD100BEBC82 /* CGM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4309786D1E73DAD100BEBC82 /* CGM.swift */; }; + 430D85891F44037000AF2D4F /* HUDViewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 430D85881F44037000AF2D4F /* HUDViewTableViewCell.swift */; }; 430DA58E1D4AEC230097D1CA /* NSBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 430DA58D1D4AEC230097D1CA /* NSBundle.swift */; }; 430DA5901D4B0E4C0097D1CA /* MySentryPumpStatusMessageBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 430DA58F1D4B0E4C0097D1CA /* MySentryPumpStatusMessageBody.swift */; }; 4311FB9B1F37FE1B00D4C0A7 /* TitleSubtitleTextFieldTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4311FB9A1F37FE1B00D4C0A7 /* TitleSubtitleTextFieldTableViewCell.swift */; }; @@ -377,6 +378,7 @@ 4309786B1E73D2F500BEBC82 /* it.lproj */ = {isa = PBXFileReference; lastKnownFileType = folder; path = it.lproj; sourceTree = ""; }; 4309786D1E73DAD100BEBC82 /* CGM.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGM.swift; sourceTree = ""; }; 430C1ABC1E5568A80067F1AE /* StatusChartsManager+LoopKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatusChartsManager+LoopKit.swift"; sourceTree = ""; }; + 430D85881F44037000AF2D4F /* HUDViewTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HUDViewTableViewCell.swift; sourceTree = ""; }; 430DA58D1D4AEC230097D1CA /* NSBundle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSBundle.swift; sourceTree = ""; }; 430DA58F1D4B0E4C0097D1CA /* MySentryPumpStatusMessageBody.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MySentryPumpStatusMessageBody.swift; sourceTree = ""; }; 4311FB9A1F37FE1B00D4C0A7 /* TitleSubtitleTextFieldTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TitleSubtitleTextFieldTableViewCell.swift; sourceTree = ""; }; @@ -935,6 +937,7 @@ 4346D1E61C77F5FE00ABAFE3 /* ChartTableViewCell.swift */, 431A8C3F1EC6E8AB00823B9C /* CircleMaskView.swift */, 43D381611EBD9759007F8C8F /* HeaderValuesTableViewCell.swift */, + 430D85881F44037000AF2D4F /* HUDViewTableViewCell.swift */, 438D42FA1D7D11A4003244B0 /* PredictionInputEffectTableViewCell.swift */, 43A5676A1C96155700334FAC /* SwitchTableViewCell.swift */, 43F64DD81D9C92C900D24DC6 /* TitleSubtitleTableViewCell.swift */, @@ -1605,6 +1608,7 @@ 435CB6291F37B01300C320C7 /* InsulinModelSettings.swift in Sources */, 431A8C401EC6E8AB00823B9C /* CircleMaskView.swift in Sources */, 439897371CD2F80600223065 /* AnalyticsManager.swift in Sources */, + 430D85891F44037000AF2D4F /* HUDViewTableViewCell.swift in Sources */, 43A51E211EB6DBDD000736CC /* ChartsTableViewController.swift in Sources */, 4346D1F61C78501000ABAFE3 /* ChartPoint+Loop.swift in Sources */, 438849EE1D2A1EBB003B3F23 /* MLabService.swift in Sources */, diff --git a/Loop/Base.lproj/Main.storyboard b/Loop/Base.lproj/Main.storyboard index 809716c6d6..6daa97981b 100644 --- a/Loop/Base.lproj/Main.storyboard +++ b/Loop/Base.lproj/Main.storyboard @@ -28,20 +28,21 @@ - + - + + - + @@ -58,14 +59,14 @@ - - + @@ -292,18 +293,21 @@ - + + + + - + @@ -324,7 +328,7 @@ - + @@ -582,23 +586,30 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -718,7 +729,6 @@ - @@ -771,14 +781,14 @@ @@ -797,13 +807,13 @@ - + + + + + diff --git a/LoopUI/Managers/StatusChartsManager.swift b/LoopUI/Managers/StatusChartsManager.swift index 6e88042864..1e538b7977 100644 --- a/LoopUI/Managers/StatusChartsManager.swift +++ b/LoopUI/Managers/StatusChartsManager.swift @@ -23,7 +23,10 @@ public final class StatusChartsManager { self.colors = colors self.chartSettings = settings - axisLabelSettings = ChartLabelSettings(font: UIFont.preferredFont(forTextStyle: UIFontTextStyle.caption1), fontColor: colors.axisLabel) + axisLabelSettings = ChartLabelSettings( + font: .systemFont(ofSize: 14), // caption1, but hard-coded until axis can scale with type preference + fontColor: colors.axisLabel + ) guideLinesLayerSettings = ChartGuideLinesLayerSettings(linesColor: colors.grid) } @@ -102,6 +105,13 @@ public final class StatusChartsManager { } } + /// The latest allowed date on the X-axis + public var maxEndDate = Date.distantFuture { + didSet { + endDate = min(endDate, maxEndDate) + } + } + /// Updates the endDate using a new candidate date /// /// Dates are rounded up to the next hour. @@ -111,7 +121,15 @@ public final class StatusChartsManager { if date > endDate { var components = DateComponents() components.minute = 0 - endDate = Calendar.current.nextDate(after: date, matching: components, matchingPolicy: .strict, direction: .forward) ?? date + endDate = min( + maxEndDate, + Calendar.current.nextDate( + after: date, + matching: components, + matchingPolicy: .strict, + direction: .forward + ) ?? date + ) } } diff --git a/LoopUI/Views/HUDView.swift b/LoopUI/Views/HUDView.swift index 7e92062c76..af89b39068 100644 --- a/LoopUI/Views/HUDView.swift +++ b/LoopUI/Views/HUDView.swift @@ -8,7 +8,7 @@ import UIKit -public class HUDView: UIStackView, NibLoadable { +public class HUDView: UIView, NibLoadable { @IBOutlet public weak var loopCompletionHUD: LoopCompletionHUDView! @IBOutlet public weak var glucoseHUD: GlucoseHUDView! @IBOutlet public weak var basalRateHUD: BasalRateHUDView! @@ -32,7 +32,7 @@ public class HUDView: UIStackView, NibLoadable { setup() } - public required init(coder aDecoder: NSCoder) { + public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setup() } diff --git a/LoopUI/Views/LoopCompletionHUDView.swift b/LoopUI/Views/LoopCompletionHUDView.swift index 03fce31072..1a5603640e 100644 --- a/LoopUI/Views/LoopCompletionHUDView.swift +++ b/LoopUI/Views/LoopCompletionHUDView.swift @@ -132,7 +132,17 @@ public final class LoopCompletionHUDView: BaseHUDView { } if let timeString = formatter.string(from: ago) { - caption.text = String(format: NSLocalizedString("%@ ago", comment: "Format string describing the time interval since the last completion date. (1: The localized date components"), timeString) + switch traitCollection.preferredContentSizeCategory { + case UIContentSizeCategory.extraSmall, + UIContentSizeCategory.small, + UIContentSizeCategory.medium, + UIContentSizeCategory.large: + // Use a longer form only for smaller text sizes + caption.text = String(format: NSLocalizedString("%@ ago", comment: "Format string describing the time interval since the last completion date. (1: The localized date components"), timeString) + default: + caption.text = timeString + } + accessibilityLabel = String(format: NSLocalizedString("Loop ran %@ ago", comment: "Accessbility format label describing the time interval since the last completion date. (1: The localized date components)"), timeString) } else { caption.text = "—" diff --git a/WatchApp Extension/ExtensionDelegate.swift b/WatchApp Extension/ExtensionDelegate.swift index de3c30d510..c326392944 100644 --- a/WatchApp Extension/ExtensionDelegate.swift +++ b/WatchApp Extension/ExtensionDelegate.swift @@ -101,8 +101,11 @@ final class ExtensionDelegate: NSObject, WKExtensionDelegate { default: break } - - task.setTaskCompleted() + #if swift(>=3.2) + task.setTaskCompletedWithSnapshot(false) + #else + task.setTaskCompleted() + #endif } } @@ -110,7 +113,13 @@ final class ExtensionDelegate: NSObject, WKExtensionDelegate { private func completePendingConnectivityTasksIfNeeded() { if WCSession.default().activationState == .activated && !WCSession.default().hasContentPending { - pendingConnectivityTasks.forEach { $0.setTaskCompleted() } + pendingConnectivityTasks.forEach { + #if swift(>=3.2) + $0.setTaskCompletedWithSnapshot(false) + #else + $0.setTaskCompleted() + #endif + } pendingConnectivityTasks.removeAll() } } From ec90b7d2415ee1d2bd56ba0a34ec99be0cc16921 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sat, 2 Sep 2017 14:56:00 -0500 Subject: [PATCH 2/2] Font scaling fixes --- Loop/Views/HUDViewTableViewCell.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Loop/Views/HUDViewTableViewCell.swift diff --git a/Loop/Views/HUDViewTableViewCell.swift b/Loop/Views/HUDViewTableViewCell.swift new file mode 100644 index 0000000000..2689ffc32f --- /dev/null +++ b/Loop/Views/HUDViewTableViewCell.swift @@ -0,0 +1,15 @@ +// +// HUDViewTableViewCell.swift +// Loop +// +// Copyright © 2017 LoopKit Authors. All rights reserved. +// + +import UIKit +import LoopUI + +class HUDViewTableViewCell: UITableViewCell { + + @IBOutlet var hudView: HUDView! + +}