Bläddra i källkod

Improve watch bolus and recommendation handling
* Reset variables on home view appear
* Remove a 0 value guard when fetching recommendation from phone
* Extending onChange handler to check for delta, and allow updating if new rec
* Add animation for crown dial icon in confirm view
* Remove unnecessary guard when handling incoming progress update messages

Deniz Cengiz 1 år sedan
förälder
incheckning
7e2ab74d97

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

@@ -103,7 +103,11 @@ struct BolusConfirmationView: View {
                         .wristLocation == .left ? "digitalcrown.arrow.clockwise.fill" : "digitalcrown.arrow.counterclockwise.fill"
                 )
                 .symbolRenderingMode(.palette)
-                .foregroundStyle(Color.primary, Color.insulin)
+                .foregroundStyle(Color.insulin, Color.primary)
+                .symbolEffect(
+                    .variableColor.reversing,
+                    options: .speed(100).repeating
+                )
             }
         }
         .blur(radius: state.showBolusProgressOverlay ? 3 : 0)

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

@@ -160,8 +160,9 @@ struct BolusInputView: View {
             }
         }
         // Add onChange to update bolus amount when recommendation changes
-        .onChange(of: state.recommendedBolus) { _, newValue in
-            if bolusAmount == 0 { // Only update if user hasn't modified the value
+        .onChange(of: state.recommendedBolus) { oldValue, newValue in
+            // Only update if user hasn't modified the value OR if recommendation hasn't changed
+            if bolusAmount == 0 || oldValue != newValue {
                 bolusAmount = Double(truncating: NSDecimalNumber(decimal: newValue))
             }
         }

+ 1 - 1
Trio Watch App Extension/Views/BolusProgressOverlay.swift

@@ -47,7 +47,7 @@ struct BolusProgressOverlay: View {
                 .padding()
             }
             .padding()
-            .background(Color.black.opacity(0.8))
+            .background(Color.black.opacity(0.9))
             .cornerRadius(10)
         }
         .scenePadding()

+ 5 - 0
Trio Watch App Extension/Views/TrioMainWatchView.swift

@@ -92,8 +92,13 @@ struct TrioMainWatchView: View {
                     .tag(1)
             }
             .onAppear {
+                // Hard reset variables when main view appears
+                /// Reset `bolusProgress` and `activeBolusAmount` to ensure no stale bolus progressbar is stuck on home view
                 state.bolusProgress = 0
                 state.activeBolusAmount = 0
+                /// Reset `bolusAmount` and `recommendedBolus` to ensure no stale / old value is set when user opens bolus input or meal combo the next time.
+                state.bolusAmount = 0
+                state.recommendedBolus = 0
             }
             .background(trioBackgroundColor)
             .tabViewStyle(.verticalPage)

+ 1 - 3
Trio Watch App Extension/WatchState+Requests.swift

@@ -145,9 +145,7 @@ extension WatchState {
             print("Error requesting bolus recommendation: \(error.localizedDescription)")
         }
 
-        if bolusAmount == 0 {
-            showBolusCalculationProgress = true
-        }
+        showBolusCalculationProgress = true
     }
 
     func requestWatchStateUpdate() {

+ 2 - 14
Trio Watch App Extension/WatchState.swift

@@ -216,13 +216,7 @@ import WatchConnectivity
                 DispatchQueue.main.async {
                     if !self.isBolusCanceled {
                         self.bolusProgress = progress
-
-                        // we only need to grab the active bolus amount from the phone if it is a phone-invoked bolus
-                        // when it comes from the watch, we already have it stored and available
-                        if self.activeBolusAmount == 0 {
-                            self.activeBolusAmount = activeBolusAmount
-                        }
-
+                        self.activeBolusAmount = activeBolusAmount
                         self.deliveredAmount = deliveredAmount
                     }
                 }
@@ -313,13 +307,7 @@ import WatchConnectivity
                 DispatchQueue.main.async {
                     if !self.isBolusCanceled {
                         self.bolusProgress = progress
-
-                        // we only need to grab the active bolus amount from the phone if it is a phone-invoked bolus
-                        // when it comes from the watch, we already have it stored and available
-                        if self.activeBolusAmount == 0 {
-                            self.activeBolusAmount = activeBolusAmount
-                        }
-
+                        self.activeBolusAmount = activeBolusAmount
                         self.deliveredAmount = deliveredAmount
                     }
                 }