@@ -80,6 +80,10 @@ class ChartsTableViewController: UITableViewController, UIGestureRecognizerDeleg
8080 override func viewDidLoad( ) {
8181 super. viewDidLoad ( )
8282
83+ if let unit = self . deviceManager. loopManager. glucoseStore. preferredUnit {
84+ self . charts. glucoseUnit = unit
85+ }
86+
8387 let notificationCenter = NotificationCenter . default
8488 notificationObservers += [
8589 notificationCenter. addObserver ( forName: . UIApplicationWillResignActive, object: UIApplication . shared, queue: . main) { [ weak self] _ in
@@ -138,17 +142,26 @@ class ChartsTableViewController: UITableViewController, UIGestureRecognizerDeleg
138142 }
139143 }
140144
141- @objc func unitPreferencesDidChange( _ note: Notification ) {
145+ @objc private func unitPreferencesDidChange( _ note: Notification ) {
142146 DispatchQueue . main. async {
143147 if let unit = self . deviceManager. loopManager. glucoseStore. preferredUnit {
148+ let didChange = unit != self . charts. glucoseUnit
144149 self . charts. glucoseUnit = unit
150+
151+ if didChange {
152+ self . glucoseUnitDidChange ( )
153+ }
145154 }
146155 self . log. debug ( " [reloadData] for HealthKit unit preference change " )
147156 self . reloadData ( )
148157 }
149158 }
150159
151- var charts = StatusChartsManager ( colors: . default, settings: . default)
160+ func glucoseUnitDidChange( ) {
161+ // To override.
162+ }
163+
164+ let charts = StatusChartsManager ( colors: . default, settings: . default)
152165
153166 // References to registered notification center observers
154167 var notificationObservers : [ Any ] = [ ]
0 commit comments