88
99import UIKit
1010import HealthKit
11+ import LoopKit
12+
1113
1214class PredictionTableViewController : UITableViewController , IdentifiableClass {
1315
@@ -85,12 +87,6 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass {
8587
8688 var dataManager : DeviceDataManager !
8789
88- private var active = true {
89- didSet {
90- reloadData ( )
91- }
92- }
93-
9490 private lazy var charts : StatusChartsManager = {
9591 let charts = StatusChartsManager ( )
9692
@@ -102,6 +98,14 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass {
10298 return charts
10399 } ( )
104100
101+ private var retrospectivePredictedGlucose : [ GlucoseValue ] ?
102+
103+ private var active = true {
104+ didSet {
105+ reloadData ( )
106+ }
107+ }
108+
105109 private var needsRefresh = true
106110
107111 private var visible = false {
@@ -149,11 +153,12 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass {
149153 }
150154
151155 dispatch_group_enter ( reloadGroup)
152- dataManager. loopManager. getLoopStatus { ( predictedGlucose, _ , _, _, _, _, error) in
156+ dataManager. loopManager. getLoopStatus { ( predictedGlucose, retrospectivePredictedGlucose , _, _, _, _, error) in
153157 if error != nil {
154158 self . needsRefresh = true
155159 }
156160
161+ self . retrospectivePredictedGlucose = retrospectivePredictedGlucose
157162 self . charts. predictedGlucoseValues = predictedGlucose ?? [ ]
158163
159164 dispatch_group_leave ( reloadGroup)
@@ -180,7 +185,7 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass {
180185 self . charts. prerender ( )
181186
182187 self . tableView. reloadSections ( NSIndexSet ( indexesInRange: NSMakeRange ( Section . charts. rawValue, 1 ) ) ,
183- withRowAnimation: animated ? . Fade : . None
188+ withRowAnimation: . None
184189 )
185190
186191 self . reloading = false
@@ -242,11 +247,29 @@ class PredictionTableViewController: UITableViewController, IdentifiableClass {
242247 let ( input, selected) = selectedInputs [ indexPath. row]
243248
244249 cell. titleLabel? . text = input. localizedTitle
245- cell. subtitleLabel? . text = input. localizedDescription ( forGlucoseUnit: charts. glucoseUnit)
246250 cell. accessoryType = selected ? . Checkmark : . None
247-
248251 cell. enabled = input != . retrospection || dataManager. loopManager. retrospectiveCorrectionEnabled
249252
253+ var subtitleText = input. localizedDescription ( forGlucoseUnit: charts. glucoseUnit)
254+
255+ if input == . retrospection,
256+ let startGlucose = retrospectivePredictedGlucose? . first,
257+ let endGlucose = retrospectivePredictedGlucose? . last,
258+ let currentGlucose = self . dataManager. glucoseStore? . latestGlucose
259+ {
260+ let formatter = NSNumberFormatter . glucoseFormatter ( for: charts. glucoseUnit)
261+ let values = [ startGlucose, endGlucose, currentGlucose] . map { formatter. stringFromNumber ( $0. quantity. doubleValueForUnit ( charts. glucoseUnit) ) ?? " ? " }
262+
263+ let retro = String (
264+ format: NSLocalizedString ( " Last comparison: %1$@ → %2$@ vs %3$@ " , comment: " Format string describing retrospective glucose prediction comparison. (1: Previous glucose)(2: Predicted glucose)(3: Actual glucose) " ) ,
265+ values [ 0 ] , values [ 1 ] , values [ 2 ]
266+ )
267+
268+ subtitleText = String ( format: " %@ \n %@ " , subtitleText, retro)
269+ }
270+
271+ cell. subtitleLabel? . text = subtitleText
272+
250273 cell. contentView. layoutMargins. left = tableView. separatorInset. left
251274
252275 return cell
0 commit comments