Browse Source

Optional Big BG Watch View

(cherry picked from commit 74cfbace389db4cb4373109e734826a99b390756)
Jon Mårtensson 3 years ago
parent
commit
7008235966
1 changed files with 53 additions and 4 deletions
  1. 53 4
      FreeAPSWatch WatchKit Extension/Views/MainView.swift

+ 53 - 4
FreeAPSWatch WatchKit Extension/Views/MainView.swift

@@ -17,6 +17,9 @@ struct MainView: View {
     @GestureState var isDetectingLongPress = false
     @State var completedLongPress = false
 
+    @State var completedLongPressOfBG = false
+    @GestureState var isDetectingLongPressOfBG = false
+
     private var healthStore = HKHealthStore()
     let heartRateQuantity = HKUnit(from: "count/min")
 
@@ -33,9 +36,13 @@ struct MainView: View {
                 }
             }
             VStack {
-                header
-                Spacer()
-                buttons
+                if !completedLongPressOfBG {
+                    header
+                    Spacer()
+                    buttons
+                } else {
+                    bigHeader
+                }
             }
 
             if state.isConfirmationViewActive {
@@ -153,7 +160,36 @@ struct MainView: View {
             }
             Spacer()
                 .onAppear(perform: start)
-        }.padding()
+        }
+        .padding()
+        // .scaleEffect(isDetectingLongPressOfBG ? 3 : 1)
+        .gesture(longPresBGs)
+    }
+
+    var bigHeader: some View {
+        VStack(alignment: .center) {
+            HStack {
+                Text(state.glucose).font(.custom("Big BG", size: 55))
+                Text(state.trend)
+                    .scaledToFill()
+                    .minimumScaleFactor(0.5)
+            }
+            Text(state.delta).font(.caption2).foregroundColor(.gray)
+
+            Spacer()
+            Spacer()
+
+            HStack {
+                Circle().stroke(color, lineWidth: 5).frame(width: 26, height: 26).padding(10)
+            }
+
+            if state.lastLoopDate != nil {
+                Text(timeString).font(.caption2).foregroundColor(.gray)
+            } else {
+                Text("--").font(.caption2).foregroundColor(.gray)
+            }
+        } // .scaleEffect(isDetectingLongPressOfBG ? 3 : 1)
+        .gesture(longPresBGs)
     }
 
     var longPress: some Gesture {
@@ -169,6 +205,19 @@ struct MainView: View {
             }
     }
 
+    var longPresBGs: some Gesture {
+        LongPressGesture(minimumDuration: 1)
+            .updating($isDetectingLongPressOfBG) { currentState, gestureState,
+                _ in
+                gestureState = currentState
+            }
+            .onEnded { _ in
+                if completedLongPressOfBG {
+                    completedLongPressOfBG = false
+                } else { completedLongPressOfBG = true }
+            }
+    }
+
     var buttons: some View {
         HStack(alignment: .center) {
             NavigationLink(isActive: $state.isCarbsViewActive) {