Explorar el Código

Add overlay to bolus views; minor clean up of files

Deniz Cengiz hace 1 año
padre
commit
3662200638

+ 16 - 0
Trio Watch App Extension/Helper+Extensions.swift

@@ -0,0 +1,16 @@
+import Foundation
+import SwiftUI
+
+extension Binding where Value == Int {
+    func doubleBinding() -> Binding<Double> {
+        Binding<Double>(
+            get: { Double(self.wrappedValue) },
+            set: { self.wrappedValue = Int($0) }
+        )
+    }
+}
+
+extension Color {
+    static let bgDarkBlue = Color("Background_DarkBlue")
+    static let bgDarkerDarkBlue = Color("Background_DarkerDarkBlue")
+}

+ 15 - 0
Trio Watch App Extension/NavigationState.swift

@@ -0,0 +1,15 @@
+import SwiftUI
+
+class NavigationState: ObservableObject {
+    @Published var path = NavigationPath() // Tracks the navigation stack
+
+    func resetToRoot() {
+        path.removeLast(path.count) // Clears the navigation stack to return to root
+    }
+}
+
+enum NavigationDestinations: String {
+    case carbInput
+    case bolusInput
+    case bolusConfirm
+}

+ 16 - 0
Trio Watch App Extension/OverlayState.swift

@@ -0,0 +1,16 @@
+import SwiftUI
+
+class OverlayState: ObservableObject {
+    @Published var isVisible: Bool = false
+    @Published var overlayContent = AnyView(EmptyView()) // Holds the content of the overlay
+
+    func showOverlay<Content: View>(_ content: Content) {
+        overlayContent = AnyView(content)
+        isVisible = true
+    }
+
+    func hideOverlay() {
+        isVisible = false
+        overlayContent = AnyView(EmptyView())
+    }
+}

+ 10 - 0
Trio Watch App Extension/PressableIconButtonStyle.swift

@@ -0,0 +1,10 @@
+import SwiftUI
+
+struct PressableIconButtonStyle: ButtonStyle {
+    func makeBody(configuration: Configuration) -> some View {
+        configuration.label
+            .background(Color.clear)
+            .opacity(configuration.isPressed ? 0.3 : 1.0) // Change opacity when pressed
+            .animation(.easeInOut(duration: 0.25), value: configuration.isPressed) // Smooth transition
+    }
+}

+ 7 - 0
Trio Watch App Extension/Views/BolusConfirmationView.swift

@@ -100,5 +100,12 @@ struct BolusConfirmationView: View {
                     .foregroundStyle(Color.white)
                     .foregroundStyle(Color.white)
             }
             }
         }
         }
+        .blur(radius: state.bolusProgress > 0 && state.bolusProgress < 1.0 && !state.isBolusCanceled ? 3 : 0)
+        .overlay {
+            if state.bolusProgress > 0 && state.bolusProgress < 1.0 && !state.isBolusCanceled {
+                BolusProgressOverlay(state: state)
+                    .transition(.opacity)
+            }
+        }
     }
     }
 }
 }

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

@@ -103,6 +103,13 @@ struct BolusInputView: View {
                     .clipShape(Circle())
                     .clipShape(Circle())
             }
             }
         }
         }
+        .blur(radius: state.bolusProgress > 0 && state.bolusProgress < 1.0 && !state.isBolusCanceled ? 3 : 0)
+        .overlay {
+            if state.bolusProgress > 0 && state.bolusProgress < 1.0 && !state.isBolusCanceled {
+                BolusProgressOverlay(state: state)
+                    .transition(.opacity)
+            }
+        }
     }
     }
 }
 }
 
 

+ 30 - 31
Trio Watch App Extension/Views/BolusProgressOverlay.swift

@@ -2,7 +2,6 @@ import SwiftUI
 
 
 struct BolusProgressOverlay: View {
 struct BolusProgressOverlay: View {
     let state: WatchState
     let state: WatchState
-    @ObservedObject var navigationState: NavigationState
 
 
     private let progressGradient = LinearGradient(
     private let progressGradient = LinearGradient(
         colors: [
         colors: [
@@ -17,42 +16,42 @@ struct BolusProgressOverlay: View {
     )
     )
 
 
     var body: some View {
     var body: some View {
-        if state.bolusProgress > 0 && state.bolusProgress < 1.0 && !state.isBolusCanceled {
+        VStack(spacing: 10) {
             VStack {
             VStack {
-                Spacer()
-                VStack(spacing: 4) {
-                    HStack {
-                        ProgressView(value: state.bolusProgress, total: 1.0)
-                            .tint(progressGradient)
+                Text("Bolusing")
+                    .font(.footnote)
+                    .foregroundStyle(.secondary)
+                    .padding(.top)
+
+                ProgressView(value: state.bolusProgress, total: 1.0)
+                    .tint(progressGradient)
 
 
-                        Button(action: {
-                            state.sendCancelBolusRequest()
-                            navigationState.resetToRoot()
-                        }) {
-                            Image(systemName: "xmark.circle.fill")
-                                .foregroundStyle(.red)
-                                .font(.system(size: 20))
-                        }
-                        .buttonStyle(.plain)
-                    }
+                Text(String(
+                    format: "%.1f U of %.1f U",
+                    state.bolusProgress * state.activeBolusAmount,
+                    state.activeBolusAmount
+                ))
+                    .font(.footnote)
+                    .foregroundStyle(.secondary)
+
+                Spacer()
 
 
-                    Text(String(
-                        format: "%.1f U of %.1f U",
-                        state.bolusProgress * state.activeBolusAmount,
-                        state.activeBolusAmount
-                    ))
-                        .font(.caption2)
-                        .foregroundStyle(.secondary)
+                Button(action: {
+                    state.sendCancelBolusRequest()
+                }) {
+                    Text("Cancel Bolus")
                 }
                 }
-                .padding()
-                .background(Color.black.opacity(0.7))
-                .cornerRadius(10)
+                .buttonStyle(.bordered)
                 .padding()
                 .padding()
             }
             }
-            .onChange(of: state.bolusProgress) { _, newProgress in
-                if newProgress >= 1.0 {
-                    state.activeBolusAmount = 0 // Reset only when bolus is complete
-                }
+            .padding()
+            .background(Color.black.opacity(0.8))
+            .cornerRadius(10)
+        }
+        .scenePadding()
+        .onChange(of: state.bolusProgress) { _, newProgress in
+            if newProgress >= 1.0 {
+                state.activeBolusAmount = 0 // Reset only when bolus is complete
             }
             }
         }
         }
     }
     }

+ 0 - 9
Trio Watch App Extension/Views/TreatmentMenuView.swift

@@ -87,12 +87,3 @@ enum TreatmentOption: String, CaseIterable, Identifiable {
         }
         }
     }
     }
 }
 }
-
-struct PressableIconButtonStyle: ButtonStyle {
-    func makeBody(configuration: Configuration) -> some View {
-        configuration.label
-            .background(Color.clear)
-            .opacity(configuration.isPressed ? 0.3 : 1.0) // Change opacity when pressed
-            .animation(.easeInOut(duration: 0.25), value: configuration.isPressed) // Smooth transition
-    }
-}

+ 8 - 58
Trio Watch App Extension/Views/TrioMainWatchView.swift

@@ -1,22 +1,9 @@
 import Charts
 import Charts
 import SwiftUI
 import SwiftUI
 
 
-class NavigationState: ObservableObject {
-    @Published var path = NavigationPath() // Tracks the navigation stack
-
-    func resetToRoot() {
-        path.removeLast(path.count) // Clears the navigation stack to return to root
-    }
-}
-
-enum NavigationDestinations: String {
-    case carbInput
-    case bolusInput
-    case bolusConfirm
-}
-
 struct TrioMainWatchView: View {
 struct TrioMainWatchView: View {
-    @StateObject private var navigationState = NavigationState() // Shared navigation state
+    // Shared navigation state
+    @StateObject private var navigationState = NavigationState()
     @State private var state = WatchState()
     @State private var state = WatchState()
 
 
     // misc
     // misc
@@ -146,36 +133,13 @@ struct TrioMainWatchView: View {
                     )
                     )
                 }
                 }
             }
             }
-            .overlay(
-                BolusProgressOverlay(state: state, navigationState: navigationState)
-            )
-        }
-    }
-
-    struct WatchOSButtonStyle: ButtonStyle {
-        var backgroundGradient = LinearGradient(colors: [
-            Color(red: 0.721, green: 0.341, blue: 1),
-            Color(red: 0.486, green: 0.545, blue: 0.953),
-            Color(red: 0.262, green: 0.733, blue: 0.914)
-        ], startPoint: .topLeading, endPoint: .bottomTrailing)
-        var foregroundColor: Color = .white
-        var fontSize: Font = .title2
-
-        private var is40mm: Bool {
-            let size = WKInterfaceDevice.current().screenBounds.size
-            return size.height < 225 && size.width < 185
         }
         }
-
-        func makeBody(configuration: Configuration) -> some View {
-            configuration.label
-                .font(fontSize)
-                .fontWeight(is40mm ? .medium : .semibold)
-                .padding(is40mm ? 6 : 8)
-                .background(
-                    backgroundGradient.opacity(configuration.isPressed ? 0.8 : 1.0)
-                )
-                .clipShape(Circle())
-                .animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
+        .blur(radius: state.bolusProgress > 0 && state.bolusProgress < 1.0 && !state.isBolusCanceled ? 3 : 0)
+        .overlay {
+            if state.bolusProgress > 0 && state.bolusProgress < 1.0 && !state.isBolusCanceled {
+                BolusProgressOverlay(state: state)
+                    .transition(.opacity)
+            }
         }
         }
     }
     }
 
 
@@ -214,20 +178,6 @@ struct TrioMainWatchView: View {
     }
     }
 }
 }
 
 
-extension Binding where Value == Int {
-    func doubleBinding() -> Binding<Double> {
-        Binding<Double>(
-            get: { Double(self.wrappedValue) },
-            set: { self.wrappedValue = Int($0) }
-        )
-    }
-}
-
-extension Color {
-    static let bgDarkBlue = Color("Background_DarkBlue")
-    static let bgDarkerDarkBlue = Color("Background_DarkerDarkBlue")
-}
-
 #Preview {
 #Preview {
     TrioMainWatchView()
     TrioMainWatchView()
 }
 }

+ 28 - 0
Trio Watch App Extension/WatchOSButtonStyle.swift

@@ -0,0 +1,28 @@
+import SwiftUI
+
+struct WatchOSButtonStyle: ButtonStyle {
+    var backgroundGradient = LinearGradient(colors: [
+        Color(red: 0.721, green: 0.341, blue: 1),
+        Color(red: 0.486, green: 0.545, blue: 0.953),
+        Color(red: 0.262, green: 0.733, blue: 0.914)
+    ], startPoint: .topLeading, endPoint: .bottomTrailing)
+    var foregroundColor: Color = .white
+    var fontSize: Font = .title2
+
+    private var is40mm: Bool {
+        let size = WKInterfaceDevice.current().screenBounds.size
+        return size.height < 225 && size.width < 185
+    }
+
+    func makeBody(configuration: Configuration) -> some View {
+        configuration.label
+            .font(fontSize)
+            .fontWeight(is40mm ? .medium : .semibold)
+            .padding(is40mm ? 6 : 8)
+            .background(
+                backgroundGradient.opacity(configuration.isPressed ? 0.8 : 1.0)
+            )
+            .clipShape(Circle())
+            .animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
+    }
+}

+ 16 - 0
Trio.xcodeproj/project.pbxproj

@@ -452,6 +452,10 @@
 		DD32CF9E2CC824C5003686D6 /* TrioRemoteControl+Override.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD32CF9D2CC824C2003686D6 /* TrioRemoteControl+Override.swift */; };
 		DD32CF9E2CC824C5003686D6 /* TrioRemoteControl+Override.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD32CF9D2CC824C2003686D6 /* TrioRemoteControl+Override.swift */; };
 		DD32CFA02CC824D6003686D6 /* TrioRemoteControl+APNS.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD32CF9F2CC824D3003686D6 /* TrioRemoteControl+APNS.swift */; };
 		DD32CFA02CC824D6003686D6 /* TrioRemoteControl+APNS.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD32CF9F2CC824D3003686D6 /* TrioRemoteControl+APNS.swift */; };
 		DD32CFA22CC824E2003686D6 /* TrioRemoteControl+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD32CFA12CC824E1003686D6 /* TrioRemoteControl+Helpers.swift */; };
 		DD32CFA22CC824E2003686D6 /* TrioRemoteControl+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD32CFA12CC824E1003686D6 /* TrioRemoteControl+Helpers.swift */; };
+		DD3A3CE32D29C49500AE478E /* NavigationState.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3A3CE22D29C49500AE478E /* NavigationState.swift */; };
+		DD3A3CE72D29C93F00AE478E /* Helper+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3A3CE62D29C93F00AE478E /* Helper+Extensions.swift */; };
+		DD3A3CE92D29C97800AE478E /* WatchOSButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3A3CE82D29C97800AE478E /* WatchOSButtonStyle.swift */; };
+		DD3A3CEB2D29C9AB00AE478E /* PressableIconButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3A3CEA2D29C9AB00AE478E /* PressableIconButtonStyle.swift */; };
 		DD5DC9F12CF3D97C00AB8703 /* AdjustmentsStateModel+Overrides.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5DC9F02CF3D96E00AB8703 /* AdjustmentsStateModel+Overrides.swift */; };
 		DD5DC9F12CF3D97C00AB8703 /* AdjustmentsStateModel+Overrides.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5DC9F02CF3D96E00AB8703 /* AdjustmentsStateModel+Overrides.swift */; };
 		DD5DC9F32CF3D9DD00AB8703 /* AdjustmentsStateModel+TempTargets.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5DC9F22CF3D9D600AB8703 /* AdjustmentsStateModel+TempTargets.swift */; };
 		DD5DC9F32CF3D9DD00AB8703 /* AdjustmentsStateModel+TempTargets.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5DC9F22CF3D9D600AB8703 /* AdjustmentsStateModel+TempTargets.swift */; };
 		DD5DC9F72CF3DA9300AB8703 /* TargetPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5DC9F62CF3DA9300AB8703 /* TargetPicker.swift */; };
 		DD5DC9F72CF3DA9300AB8703 /* TargetPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5DC9F62CF3DA9300AB8703 /* TargetPicker.swift */; };
@@ -1165,6 +1169,10 @@
 		DD32CF9D2CC824C2003686D6 /* TrioRemoteControl+Override.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TrioRemoteControl+Override.swift"; sourceTree = "<group>"; };
 		DD32CF9D2CC824C2003686D6 /* TrioRemoteControl+Override.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TrioRemoteControl+Override.swift"; sourceTree = "<group>"; };
 		DD32CF9F2CC824D3003686D6 /* TrioRemoteControl+APNS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TrioRemoteControl+APNS.swift"; sourceTree = "<group>"; };
 		DD32CF9F2CC824D3003686D6 /* TrioRemoteControl+APNS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TrioRemoteControl+APNS.swift"; sourceTree = "<group>"; };
 		DD32CFA12CC824E1003686D6 /* TrioRemoteControl+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TrioRemoteControl+Helpers.swift"; sourceTree = "<group>"; };
 		DD32CFA12CC824E1003686D6 /* TrioRemoteControl+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TrioRemoteControl+Helpers.swift"; sourceTree = "<group>"; };
+		DD3A3CE22D29C49500AE478E /* NavigationState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationState.swift; sourceTree = "<group>"; };
+		DD3A3CE62D29C93F00AE478E /* Helper+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Helper+Extensions.swift"; sourceTree = "<group>"; };
+		DD3A3CE82D29C97800AE478E /* WatchOSButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchOSButtonStyle.swift; sourceTree = "<group>"; };
+		DD3A3CEA2D29C9AB00AE478E /* PressableIconButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PressableIconButtonStyle.swift; sourceTree = "<group>"; };
 		DD5DC9F02CF3D96E00AB8703 /* AdjustmentsStateModel+Overrides.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AdjustmentsStateModel+Overrides.swift"; sourceTree = "<group>"; };
 		DD5DC9F02CF3D96E00AB8703 /* AdjustmentsStateModel+Overrides.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AdjustmentsStateModel+Overrides.swift"; sourceTree = "<group>"; };
 		DD5DC9F22CF3D9D600AB8703 /* AdjustmentsStateModel+TempTargets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AdjustmentsStateModel+TempTargets.swift"; sourceTree = "<group>"; };
 		DD5DC9F22CF3D9D600AB8703 /* AdjustmentsStateModel+TempTargets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AdjustmentsStateModel+TempTargets.swift"; sourceTree = "<group>"; };
 		DD5DC9F62CF3DA9300AB8703 /* TargetPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TargetPicker.swift; sourceTree = "<group>"; };
 		DD5DC9F62CF3DA9300AB8703 /* TargetPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TargetPicker.swift; sourceTree = "<group>"; };
@@ -2523,6 +2531,10 @@
 		BDFF7A9C2D25FA730016C40C /* Trio Watch App Extension */ = {
 		BDFF7A9C2D25FA730016C40C /* Trio Watch App Extension */ = {
 			isa = PBXGroup;
 			isa = PBXGroup;
 			children = (
 			children = (
+				DD3A3CEA2D29C9AB00AE478E /* PressableIconButtonStyle.swift */,
+				DD3A3CE82D29C97800AE478E /* WatchOSButtonStyle.swift */,
+				DD3A3CE62D29C93F00AE478E /* Helper+Extensions.swift */,
+				DD3A3CE22D29C49500AE478E /* NavigationState.swift */,
 				BDA25F1A2D26BCE800035F34 /* Views */,
 				BDA25F1A2D26BCE800035F34 /* Views */,
 				BDA25EE52D260D5800035F34 /* WatchState.swift */,
 				BDA25EE52D260D5800035F34 /* WatchState.swift */,
 				BDFF7A9E2D25FA970016C40C /* Preview Content */,
 				BDFF7A9E2D25FA970016C40C /* Preview Content */,
@@ -3975,6 +3987,7 @@
 			buildActionMask = 2147483647;
 			buildActionMask = 2147483647;
 			files = (
 			files = (
 				BDA25F222D26D62800035F34 /* BolusInputView.swift in Sources */,
 				BDA25F222D26D62800035F34 /* BolusInputView.swift in Sources */,
+				DD3A3CE32D29C49500AE478E /* NavigationState.swift in Sources */,
 				BDFF7A882D25F97D0016C40C /* TrioMainWatchView.swift in Sources */,
 				BDFF7A882D25F97D0016C40C /* TrioMainWatchView.swift in Sources */,
 				BDA25F202D26D5FE00035F34 /* CarbsInputView.swift in Sources */,
 				BDA25F202D26D5FE00035F34 /* CarbsInputView.swift in Sources */,
 				BDA25F1C2D26BD0700035F34 /* TrendShape.swift in Sources */,
 				BDA25F1C2D26BD0700035F34 /* TrendShape.swift in Sources */,
@@ -3983,10 +3996,13 @@
 				BD54A95C2D2808A300F9C1EE /* OverridePresetWatch.swift in Sources */,
 				BD54A95C2D2808A300F9C1EE /* OverridePresetWatch.swift in Sources */,
 				BD54A9592D27FB7800F9C1EE /* OverridePresetsView.swift in Sources */,
 				BD54A9592D27FB7800F9C1EE /* OverridePresetsView.swift in Sources */,
 				BDA25F1E2D26D5DD00035F34 /* GlucoseChartView.swift in Sources */,
 				BDA25F1E2D26D5DD00035F34 /* GlucoseChartView.swift in Sources */,
+				DD3A3CEB2D29C9AB00AE478E /* PressableIconButtonStyle.swift in Sources */,
 				DD6F63CC2D27F615007D94CF /* TreatmentMenuView.swift in Sources */,
 				DD6F63CC2D27F615007D94CF /* TreatmentMenuView.swift in Sources */,
+				DD3A3CE72D29C93F00AE478E /* Helper+Extensions.swift in Sources */,
 				DD246F062D2836AA0027DDE0 /* GlucoseTrendView.swift in Sources */,
 				DD246F062D2836AA0027DDE0 /* GlucoseTrendView.swift in Sources */,
 				DD8262CB2D289297009F6F62 /* BolusConfirmationView.swift in Sources */,
 				DD8262CB2D289297009F6F62 /* BolusConfirmationView.swift in Sources */,
 				BD54A9712D281A8100F9C1EE /* TempTargetPresetsView.swift in Sources */,
 				BD54A9712D281A8100F9C1EE /* TempTargetPresetsView.swift in Sources */,
+				DD3A3CE92D29C97800AE478E /* WatchOSButtonStyle.swift in Sources */,
 				BDA25EE62D260D5E00035F34 /* WatchState.swift in Sources */,
 				BDA25EE62D260D5E00035F34 /* WatchState.swift in Sources */,
 				BD04ECCE2D29952A008C5FEB /* BolusProgressOverlay.swift in Sources */,
 				BD04ECCE2D29952A008C5FEB /* BolusProgressOverlay.swift in Sources */,
 			);
 			);