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
6 changes: 3 additions & 3 deletions Loop/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,14 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="LXC-eC-kw9">
<frame key="frameInset" minX="15" minY="12" width="32" height="20"/>
<frame key="frameInset" minX="15" minY="13" width="31.5" height="19.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<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="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="LjQ-f8-8VW">
<frame key="frameInset" minX="318" minY="12" width="42" height="20"/>
<frame key="frameInset" minX="318.5" minY="13" width="41.5" height="19.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.55686274509803924" green="0.55686274509803924" blue="0.57647058823529407" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand All @@ -543,7 +543,7 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Glucose" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tuw-av-A3x">
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="17"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
Expand Down
15 changes: 8 additions & 7 deletions Loop/View Controllers/PredictionTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass {
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

if !visible {
needsRefresh = true
needsRefresh = true
if visible {
reloadData(animated: false)
}
}

Expand Down Expand Up @@ -177,11 +178,11 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass {
}

self.charts.prerender()
self.tableView.reloadSections(IndexSet(integersIn: NSMakeRange(Section.charts.rawValue, 1).toRange() ?? 0..<0),
with: .none
)

for case let row as ChartTableViewCell in self.tableView.visibleCells {
row.reloadChart()
}

self.reloading = false
}
}
Expand Down
37 changes: 28 additions & 9 deletions Loop/View Controllers/StatusTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

if !visible {
needsRefresh = true
needsRefresh = true
if visible {
reloadData(animated: false)
}
}

Expand Down Expand Up @@ -125,6 +126,9 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize

private var reloading = false

/// Refetches all data and updates the views. Must be called on the main queue.
///
/// - parameter animated: Whether the updating should be animated if possible
private func reloadData(animated: Bool = false) {
if active && visible && needsRefresh {
needsRefresh = false
Expand All @@ -142,6 +146,8 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize

let reloadGroup = DispatchGroup()
var glucoseUnit: HKUnit?
let oldRecommendedTempBasal = self.recommendedTempBasal
var newRecommendedTempBasal: LoopDataManager.TempBasalRecommendation?

if let glucoseStore = dataManager.glucoseStore {
reloadGroup.enter()
Expand Down Expand Up @@ -172,7 +178,7 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize
}

self.charts.predictedGlucoseValues = predictedGlucose ?? []
self.recommendedTempBasal = recommendedTempBasal
newRecommendedTempBasal = recommendedTempBasal
self.lastTempBasal = lastTempBasal
self.lastLoopCompleted = lastLoopCompleted

Expand Down Expand Up @@ -248,18 +254,31 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize

self.charts.prerender()

self.tableView.reloadSections(IndexSet(integersIn: NSMakeRange(Section.charts.rawValue, 2).toRange() ?? 0..<0),
with: animated ? .fade : .none
)
// Show/hide the recommended temp basal row
self.recommendedTempBasal = newRecommendedTempBasal
switch (oldRecommendedTempBasal, newRecommendedTempBasal) {
case (let old?, let new?) where old != new:
self.tableView.reloadRows(at: [IndexPath(row: 0, section: Section.status.rawValue)], with: animated ? .top : .none)
case (.none, .some):
self.tableView.insertRows(at: [IndexPath(row: 0, section: Section.status.rawValue)], with: animated ? .top : .none)
case (.some, .none):
self.tableView.deleteRows(at: [IndexPath(row: 0, section: Section.status.rawValue)], with: animated ? .top : .none)
default:
break
}

for case let row as ChartTableViewCell in self.tableView.visibleCells {
row.reloadChart()
}

self.reloading = false
}
}
}

private enum Section: Int {
case charts = 0
case status
case status = 0
case charts

static let count = 2
}
Expand Down Expand Up @@ -384,7 +403,7 @@ final class StatusTableViewController: UITableViewController, UIGestureRecognize
case .charts:
return ChartRow.count
case .status:
return StatusRow.count
return self.recommendedTempBasal == nil ? 0 : StatusRow.count
}
}

Expand Down
4 changes: 1 addition & 3 deletions Loop/Views/ChartContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class ChartContentView: UIView {
override func layoutSubviews() {
super.layoutSubviews()

if chartView == nil || chartView!.frame != bounds {
chartView = chartGenerator?(bounds)
}
chartView = chartGenerator?(bounds)
}

var chartGenerator: ((CGRect) -> UIView?)? {
Expand Down
4 changes: 4 additions & 0 deletions Loop/Views/ChartTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ final class ChartTableViewCell: UITableViewCell {

chartContentView.chartGenerator = nil
}

func reloadChart() {
chartContentView.setNeedsLayout()
}
}