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

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

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

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