Просмотр исходного кода

Fix insulin value formatting (for bolus-related views)

Deniz Cengiz 1 год назад
Родитель
Сommit
a3d94bda58

+ 4 - 1
Trio Watch App Extension/Views/BolusConfirmationView.swift

@@ -17,6 +17,9 @@ struct BolusConfirmationView: View {
     )
     )
 
 
     var body: some View {
     var body: some View {
+        let bolusIncrement = Double(truncating: state.bolusIncrement as NSNumber)
+        let adjustedBolusAmount = floor(bolusAmount / bolusIncrement) * bolusIncrement
+
         VStack(spacing: 10) {
         VStack(spacing: 10) {
             Spacer()
             Spacer()
 
 
@@ -34,7 +37,7 @@ struct BolusConfirmationView: View {
                 HStack {
                 HStack {
                     Text("Bolus")
                     Text("Bolus")
                     Spacer()
                     Spacer()
-                    Text(String(format: "%.1f U", bolusAmount))
+                    Text(String(format: "%.2f U", adjustedBolusAmount))
                         .bold()
                         .bold()
                         .foregroundStyle(Color.insulin)
                         .foregroundStyle(Color.insulin)
                 }.padding(.horizontal)
                 }.padding(.horizontal)

+ 2 - 7
Trio Watch App Extension/Views/BolusInputView.swift

@@ -38,18 +38,14 @@ struct BolusInputView: View {
                 Spacer()
                 Spacer()
             } else {
             } else {
                 if effectiveBolusLimit == 0 {
                 if effectiveBolusLimit == 0 {
-                    VStack(spacing: 10) {
-                        Spacer()
-
+                    VStack(spacing: 8) {
                         Text("Bolus limit cannot be fetched from phone!").font(.headline)
                         Text("Bolus limit cannot be fetched from phone!").font(.headline)
                         Text("Check device settings, connect to phone, and try again.").font(.caption)
                         Text("Check device settings, connect to phone, and try again.").font(.caption)
-
-                        Spacer()
                     }
                     }
-                    .foregroundColor(.loopRed)
                     .scenePadding()
                     .scenePadding()
                 } else {
                 } else {
                     if state.carbsAmount > 0 {
                     if state.carbsAmount > 0 {
+                        // Display the current carb amount
                         HStack {
                         HStack {
                             Text("Carbs:").bold().font(.subheadline).padding(.leading)
                             Text("Carbs:").bold().font(.subheadline).padding(.leading)
                             Text("\(state.carbsAmount) g").font(.subheadline).foregroundStyle(Color.orange)
                             Text("\(state.carbsAmount) g").font(.subheadline).foregroundStyle(Color.orange)
@@ -73,7 +69,6 @@ struct BolusInputView: View {
 
 
                         Spacer()
                         Spacer()
 
 
-                        // Display the current carb amount
                         let bolusIncrement = Double(truncating: state.bolusIncrement as NSNumber)
                         let bolusIncrement = Double(truncating: state.bolusIncrement as NSNumber)
                         let adjustedBolusAmount = floor(bolusAmount / bolusIncrement) * bolusIncrement
                         let adjustedBolusAmount = floor(bolusAmount / bolusIncrement) * bolusIncrement
 
 

+ 6 - 3
Trio Watch App Extension/Views/BolusProgressOverlay.swift

@@ -17,6 +17,9 @@ struct BolusProgressOverlay: View {
     )
     )
 
 
     var body: some View {
     var body: some View {
+        let bolusIncrement = Double(truncating: state.bolusIncrement as NSNumber)
+        let adjustedBolusAmount = floor(state.activeBolusAmount / bolusIncrement) * bolusIncrement
+
         VStack(spacing: 10) {
         VStack(spacing: 10) {
             VStack {
             VStack {
                 Text("Bolusing")
                 Text("Bolusing")
@@ -28,9 +31,9 @@ struct BolusProgressOverlay: View {
                     .tint(progressGradient)
                     .tint(progressGradient)
 
 
                 Text(String(
                 Text(String(
-                    format: "%.1f U of %.1f U",
-                    state.bolusProgress * state.activeBolusAmount,
-                    state.activeBolusAmount
+                    format: "%.2f U of %.2f U",
+                    state.bolusProgress * adjustedBolusAmount,
+                    adjustedBolusAmount
                 ))
                 ))
                     .font(.footnote)
                     .font(.footnote)
                     .foregroundStyle(.secondary)
                     .foregroundStyle(.secondary)