Jon B.M пре 4 година
родитељ
комит
1b4825f87f

+ 1 - 1
FreeAPSWatch WatchKit Extension/Views/ConfirmationView.swift

@@ -51,7 +51,7 @@ struct ConfirmationView_Previews: PreviewProvider {
     }
 }
 
-private struct BlinkingView: View {
+struct BlinkingView: View {
     let count: UInt
     let size: CGFloat
 

+ 14 - 2
FreeAPSWatch WatchKit Extension/Views/MainView.swift

@@ -11,8 +11,19 @@ struct MainView: View {
     @State var isCarbsActive = false
     @State var isTargetsActive = false
     @State var isBolusActive = false
+
     var body: some View {
-        ZStack {
+        ZStack(alignment: .topLeading) {
+            if state.timerDate.timeIntervalSince(state.lastUpdate) > 10 {
+                HStack {
+                    withAnimation {
+                        BlinkingView(count: 5, size: 3)
+                            .frame(width: 14, height: 14)
+                            .padding(2)
+                    }
+                    Text("Updating...").font(.caption2).foregroundColor(.secondary)
+                }
+            }
             VStack {
                 header
                 Spacer()
@@ -26,7 +37,8 @@ struct MainView: View {
         }
         .frame(maxHeight: .infinity)
         .padding()
-        .onReceive(state.timer) { _ in
+        .onReceive(state.timer) { date in
+            state.timerDate = date
             state.requestState()
         }
         .onAppear {

+ 3 - 0
FreeAPSWatch WatchKit Extension/Views/WatchStateModel.swift

@@ -26,6 +26,8 @@ class WatchStateModel: NSObject, ObservableObject {
     @Published var isBolusViewActive = false
     @Published var isConfirmationViewActive = false
     @Published var confirmationSuccess: Bool?
+    @Published var lastUpdate: Date = .distantPast
+    @Published var timerDate = Date()
 
     private var lifetime = Set<AnyCancellable>()
     let timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
@@ -131,6 +133,7 @@ class WatchStateModel: NSObject, ObservableObject {
         cob = state.cob
         tempTargets = state.tempTargets
         bolusAfterCarbs = state.bolusAfterCarbs ?? true
+        lastUpdate = Date()
     }
 }