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
26 changes: 13 additions & 13 deletions Loop/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="SwitchTableViewCell" id="vah-ss-3Ud" customClass="SwitchTableViewCell" customModule="Loop" customModuleProvider="target">
<rect key="frame" x="0.0" y="120" width="320" height="44"/>
<rect key="frame" x="0.0" y="119.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="vah-ss-3Ud" id="D0A-EB-kmz">
<frame key="frameInset" width="320" height="43"/>
Expand All @@ -32,9 +32,9 @@
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="guo-4Z-RoO"/>
</subviews>
<constraints>
<constraint firstItem="moR-fS-DWR" firstAttribute="leading" secondItem="D0A-EB-kmz" secondAttribute="leadingMargin" constant="7" id="3Zc-7R-Uft"/>
<constraint firstItem="moR-fS-DWR" firstAttribute="leading" secondItem="D0A-EB-kmz" secondAttribute="leadingMargin" id="3Zc-7R-Uft"/>
<constraint firstItem="moR-fS-DWR" firstAttribute="top" secondItem="D0A-EB-kmz" secondAttribute="topMargin" id="Sa2-TB-EcZ"/>
<constraint firstAttribute="trailingMargin" secondItem="guo-4Z-RoO" secondAttribute="trailing" constant="7" id="gb5-W2-roe"/>
<constraint firstAttribute="trailingMargin" secondItem="guo-4Z-RoO" secondAttribute="trailing" id="gb5-W2-roe"/>
<constraint firstAttribute="bottomMargin" secondItem="moR-fS-DWR" secondAttribute="bottom" priority="750" id="j5I-H8-Otk"/>
<constraint firstItem="guo-4Z-RoO" firstAttribute="leading" secondItem="moR-fS-DWR" secondAttribute="trailing" constant="8" symbolic="YES" id="tzW-RW-90H"/>
<constraint firstItem="guo-4Z-RoO" firstAttribute="centerY" secondItem="D0A-EB-kmz" secondAttribute="centerY" id="w98-m4-irJ"/>
Expand All @@ -46,21 +46,21 @@
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="ConfigTableViewCell" textLabel="5TX-kX-nBo" detailTextLabel="m9c-SQ-djE" style="IBUITableViewCellStyleValue1" id="0EG-OG-YuT">
<rect key="frame" x="0.0" y="164" width="320" height="44"/>
<rect key="frame" x="0.0" y="163.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="0EG-OG-YuT" id="af2-sZ-CY0">
<frame key="frameInset" width="287" height="43"/>
<frame key="frameInset" width="287" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Pump ID" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="5TX-kX-nBo">
<frame key="frameInset" minX="15" minY="11" width="65" height="21"/>
<frame key="frameInset" minX="15" minY="12" width="65" height="20.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Tap to set" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="m9c-SQ-djE">
<frame key="frameInset" minX="209" minY="11" width="76" height="21"/>
<frame key="frameInset" minX="209" minY="12" width="76" height="20.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" red="0.55676333109537768" green="0.55676333109537768" blue="0.55676333109537768" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down Expand Up @@ -123,7 +123,7 @@
<rect key="frame" x="0.0" y="92" width="320" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mQk-9D-0ub" id="B1i-Pw-wSw">
<frame key="frameInset" width="320" height="269"/>
<frame key="frameInset" width="320" height="269.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FBL-RL-faM" customClass="ChartContentView" customModule="Loop" customModuleProvider="target">
Expand Down Expand Up @@ -165,7 +165,7 @@
<rect key="frame" x="0.0" y="362" width="320" height="64"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Xc2-a9-ojZ" id="a4h-tq-Rnl">
<frame key="frameInset" width="320" height="63"/>
<frame key="frameInset" width="320" height="63.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" verticalCompressionResistancePriority="751" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bIL-Ub-qYp">
Expand Down Expand Up @@ -197,7 +197,7 @@
<rect key="frame" x="0.0" y="426" width="320" height="64"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="I71-cY-0y7" id="0f9-ja-YFt">
<frame key="frameInset" width="320" height="63"/>
<frame key="frameInset" width="320" height="63.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="249" verticalHuggingPriority="252" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zbc-87-wxZ">
Expand Down Expand Up @@ -662,7 +662,7 @@
<rect key="frame" x="0.0" y="99" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="DoN-m5-O7j" id="3OB-7U-Jvb">
<frame key="frameInset" width="320" height="43"/>
<frame key="frameInset" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Recommended" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ywT-OR-NnU">
Expand Down Expand Up @@ -704,7 +704,7 @@
<rect key="frame" x="0.0" y="143" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="us0-UE-Wqz" id="2fI-OE-GLU">
<frame key="frameInset" width="320" height="43"/>
<frame key="frameInset" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Bolus" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5oA-6d-ZTL">
Expand Down Expand Up @@ -745,7 +745,7 @@
<rect key="frame" x="0.0" y="187" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="efV-tT-gC9" id="nq8-dv-ceA">
<frame key="frameInset" width="320" height="43"/>
<frame key="frameInset" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ya0-9b-ZAS">
Expand Down
10 changes: 9 additions & 1 deletion Loop/Managers/StatusChartManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ final class StatusChartsManager {

var startDate = Date()

var glucoseUnit: HKUnit = HKUnit.milligramsPerDeciliterUnit()
var glucoseUnit: HKUnit = HKUnit.milligramsPerDeciliterUnit() {
didSet {
if glucoseUnit != oldValue {
// Regenerate the glucose display points
let oldRange = glucoseDisplayRange
glucoseDisplayRange = oldRange
}
}
}

var glucoseTargetRangeSchedule: GlucoseRangeSchedule?

Expand Down
17 changes: 11 additions & 6 deletions Loop/View Controllers/SettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu

if let carbRatioSchedule = dataManager.carbRatioSchedule {
let unit = carbRatioSchedule.unit
let value = carbRatioSchedule.averageQuantity().doubleValue(for: unit)
let value = valueNumberFormatter.string(from: NSNumber(value: carbRatioSchedule.averageQuantity().doubleValue(for: unit))) ?? "—"

configCell.detailTextLabel?.text = "\(valueNumberFormatter.string(from: NSNumber(value: value))!) \(unit)/U"
configCell.detailTextLabel?.text = String(format: NSLocalizedString("%1$@ %2$@/U", comment: "Format string for carb ratio average. (1: value)(2: carb unit)"), value, unit)
} else {
configCell.detailTextLabel?.text = TapToSetString
}
Expand All @@ -214,9 +214,9 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu

if let insulinSensitivitySchedule = dataManager.insulinSensitivitySchedule {
let unit = insulinSensitivitySchedule.unit
let value = insulinSensitivitySchedule.averageQuantity().doubleValue(for: unit)
let value = valueNumberFormatter.string(from: NSNumber(value: insulinSensitivitySchedule.averageQuantity().doubleValue(for: unit))) ?? "—"

configCell.detailTextLabel?.text = "\(valueNumberFormatter.string(from: NSNumber(value: value))!) \(unit)/U"
configCell.detailTextLabel?.text = String(format: NSLocalizedString("%1$@ %2$@/U", comment: "Format string for insulin sensitivity average (1: value)(2: glucose unit)"), value, unit.glucoseUnitDisplayString)
} else {
configCell.detailTextLabel?.text = TapToSetString
}
Expand All @@ -226,17 +226,22 @@ final class SettingsTableViewController: UITableViewController, DailyValueSchedu
if let glucoseTargetRangeSchedule = dataManager.glucoseTargetRangeSchedule {
let unit = glucoseTargetRangeSchedule.unit
let value = glucoseTargetRangeSchedule.value(at: Date())
let minTarget = valueNumberFormatter.string(from: NSNumber(value: value.minValue)) ?? "—"
let maxTarget = valueNumberFormatter.string(from: NSNumber(value: value.maxValue)) ?? "—"

configCell.detailTextLabel?.text = "\(valueNumberFormatter.string(from: NSNumber(value: value.minValue))!) – \(valueNumberFormatter.string(from: NSNumber(value: value.maxValue))!) \(unit)"
configCell.detailTextLabel?.text = String(format: NSLocalizedString("%1$@ – %2$@ %3$@", comment: "Format string for glucose target range. (1: Min target)(2: Max target)(3: glucose unit)"), minTarget, maxTarget, unit.glucoseUnitDisplayString)
} else {
configCell.detailTextLabel?.text = TapToSetString
}
case .insulinActionDuration:
configCell.textLabel?.text = NSLocalizedString("Insulin Action Duration", comment: "The title text for the insulin action duration value")

if let insulinActionDuration = dataManager.insulinActionDuration {
let formatter = DateComponentsFormatter()
formatter.allowsFractionalUnits = true
formatter.allowedUnits = [.hour]

configCell.detailTextLabel?.text = "\(insulinActionDuration.hours) hours"
configCell.detailTextLabel?.text = formatter.string(from: insulinActionDuration)
} else {
configCell.detailTextLabel?.text = TapToSetString
}
Expand Down
23 changes: 16 additions & 7 deletions Loop/View Controllers/StatusTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize
components.minute = 0
let date = Date(timeIntervalSinceNow: -TimeInterval(hours: max(1, historyHours)))
charts.startDate = Calendar.current.nextDate(after: date, matching: components, matchingPolicy: .strict, direction: .backward) ?? date
charts.glucoseDisplayRange = (
min: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 100),
max: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 175)
)

let reloadGroup = DispatchGroup()
let oldRecommendedTempBasal = self.recommendedTempBasal
Expand Down Expand Up @@ -321,7 +317,16 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize
static let count = 4
}

private let charts = StatusChartsManager()
private lazy var charts: StatusChartsManager = {
let charts = StatusChartsManager()

charts.glucoseDisplayRange = (
min: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 100),
max: HKQuantity(unit: HKUnit.milligramsPerDeciliterUnit(), doubleValue: 175)
)

return charts
}()

// MARK: Glucose

Expand Down Expand Up @@ -558,11 +563,15 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch Section(rawValue: indexPath.section)! {
case .charts:
// 20: Status bar
// 44: Toolbar
let availableSize = max(tableView.bounds.width, tableView.bounds.height) - 20 - (tableView.tableHeaderView?.frame.height ?? 0) - 44

switch ChartRow(rawValue: indexPath.row)! {
case .glucose:
return 180
return max(100, 0.37 * availableSize)
case .iob, .dose, .cob:
return 110
return max(100, 0.21 * availableSize)
}
case .status:
return UITableViewAutomaticDimension
Expand Down
7 changes: 7 additions & 0 deletions Loop/Views/SwitchTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ final class SwitchTableViewCell: UITableViewCell {

@IBOutlet var `switch`: UISwitch?

override func layoutSubviews() {
super.layoutSubviews()

contentView.layoutMargins.left = separatorInset.left
contentView.layoutMargins.right = separatorInset.left
}

override func prepareForReuse() {
super.prepareForReuse()

Expand Down