Skip to content

Commit afec3c1

Browse files
Bharat Medirattaps2
authored andcommitted
Widget should always display data using the preferred dispay unit, (#434)
regardless of the units used in the StatusExtensionContext.
1 parent 22c42ce commit afec3c1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Loop Status Extension/StatusViewController.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class StatusViewController: UIViewController, NCWidgetProviding {
209209
let unit = glucose[0].unit
210210
let glucoseFormatter = NumberFormatter.glucoseFormatter(for: unit)
211211

212+
charts.glucoseUnit = unit
212213
charts.glucosePoints = glucose.map {
213214
ChartPoint(
214215
x: ChartAxisValueDate(date: $0.startDate, formatter: dateFormatter),
@@ -225,20 +226,20 @@ class StatusViewController: UIViewController, NCWidgetProviding {
225226
charts.predictedGlucosePoints = predictedGlucose.map {
226227
ChartPoint(
227228
x: ChartAxisValueDate(date: $0.startDate, formatter: dateFormatter),
228-
y: ChartAxisValueDoubleUnit($0.value, unitString: unit.unitString, formatter: glucoseFormatter)
229+
y: ChartAxisValueDoubleUnit($0.quantity.doubleValue(for: unit), unitString: unit.unitString, formatter: glucoseFormatter)
229230
)
230231
}
231232

232233
if let eventualGlucose = predictedGlucose.last {
233234
let formatter = NumberFormatter.glucoseFormatter(for: eventualGlucose.unit)
234235

235-
if let eventualGlucoseNumberString = formatter.string(from: NSNumber(value: eventualGlucose.value)) {
236+
if let eventualGlucoseNumberString = formatter.string(from: NSNumber(value: eventualGlucose.quantity.doubleValue(for: unit))) {
236237
subtitleLabel.text = String(
237238
format: NSLocalizedString(
238239
"Eventually %1$@ %2$@",
239240
comment: "The subtitle format describing eventual glucose. (1: localized glucose value description) (2: localized glucose units description)"),
240241
eventualGlucoseNumberString,
241-
eventualGlucose.unit.glucoseUnitDisplayString
242+
unit.glucoseUnitDisplayString
242243
)
243244
subtitleLabel.isHidden = false
244245
}

0 commit comments

Comments
 (0)