Skip to content

Commit

Permalink
Fix eventually glucose amount missing
Browse files Browse the repository at this point in the history
  • Loading branch information
gestrich committed May 10, 2024
1 parent b5794f5 commit 74239a8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions LoopCaregiver/LoopCaregiver/Views/Charts/ChartsListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ struct ChartsListView: View {
}

func eventualGlucose() -> String {
guard remoteDataSource.predictedGlucose.last != nil else {
guard let eventualGlucose = remoteDataSource.predictedGlucose.last else {
return ""
}

return "Eventually \(settings.glucoseDisplayUnits.shortLocalizedUnitString(avoidLineBreaking: true))"
return "Eventually \(eventualGlucose.presentableStringValue(displayUnits: settings.glucoseDisplayUnits, includeShortUnits: true))"
}

func formattedCOB() -> String {
Expand Down
3 changes: 2 additions & 1 deletion LoopCaregiver/LoopCaregiver/Views/Home/HUDView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ struct HUDView: View {
HStack {
Text(
nightscoutDataSource.currentGlucoseSample?.presentableStringValue(
displayUnits: settings.glucoseDisplayUnits
displayUnits: settings.glucoseDisplayUnits,
includeShortUnits: false
) ?? " "
)
.strikethrough(egvIsOutdated())
Expand Down
5 changes: 3 additions & 2 deletions LoopCaregiver/LoopCaregiverWatchApp/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct HomeView: View {
var body: some View {
VStack {
HStack {
Text(remoteDataSource.currentGlucoseSample?.presentableStringValue(displayUnits: settings.glucoseDisplayUnits) ?? " ")
Text(remoteDataSource.currentGlucoseSample?.presentableStringValue(displayUnits: settings.glucoseDisplayUnits, includeShortUnits: false) ?? " ")
.strikethrough(egvIsOutdated())
.font(.largeTitle)
.foregroundColor(egvValueColor())
Expand Down Expand Up @@ -90,7 +90,8 @@ struct HomeView: View {

func glucoseText() -> String {
return remoteDataSource.currentGlucoseSample?.presentableStringValue(
displayUnits: settings.glucoseDisplayUnits
displayUnits: settings.glucoseDisplayUnits,
includeShortUnits: false
) ?? " "
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ public extension NewGlucoseSample {
return quantity.doubleValue(for: displayUnits)
}

func presentableStringValue(displayUnits: HKUnit) -> String {
func presentableStringValue(displayUnits: HKUnit, includeShortUnits: Bool) -> String {
let unitInUserUnits = quantity.doubleValue(for: displayUnits)
return LocalizationUtils.presentableStringFromGlucoseAmount(unitInUserUnits, displayUnits: displayUnits)
var result = LocalizationUtils.presentableStringFromGlucoseAmount(unitInUserUnits, displayUnits: displayUnits)
if includeShortUnits {
result += " " + displayUnits.shortLocalizedUnitString(avoidLineBreaking: true)
}
return result
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct WidgetViewModel {

public var currentGlucoseText: String {
var toRet = ""
let latestGlucoseValue = latestGlucose.presentableStringValue(displayUnits: glucoseDisplayUnits)
let latestGlucoseValue = latestGlucose.presentableStringValue(displayUnits: glucoseDisplayUnits, includeShortUnits: false)
toRet += "\(latestGlucoseValue)"

if let lastGlucoseChangeFormatted {
Expand All @@ -55,7 +55,7 @@ public struct WidgetViewModel {

public var currentGlucoseNumberText: String {
var toRet = ""
let latestGlucoseValue = latestGlucose.presentableStringValue(displayUnits: glucoseDisplayUnits)
let latestGlucoseValue = latestGlucose.presentableStringValue(displayUnits: glucoseDisplayUnits, includeShortUnits: false)
toRet += "\(latestGlucoseValue)"

return toRet
Expand Down

0 comments on commit 74239a8

Please sign in to comment.