Ivan Valkou 5 лет назад
Родитель
Сommit
516bd71b69

+ 4 - 0
FreeAPS.xcodeproj/project.pbxproj

@@ -199,6 +199,7 @@
 		38E98A3025F52FF700C0CED0 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E98A2F25F52FF700C0CED0 /* Config.swift */; };
 		38E98A3725F5509500C0CED0 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E98A3625F5509500C0CED0 /* String+Extensions.swift */; };
 		38EA05DA261F6E7C0064E39B /* SimpleLogReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38EA05D9261F6E7C0064E39B /* SimpleLogReporter.swift */; };
+		38EA0600262091870064E39B /* BolusProgressViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38EA05FF262091870064E39B /* BolusProgressViewStyle.swift */; };
 		38F37828261260DC009DB701 /* Color+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38F37827261260DC009DB701 /* Color+Extensions.swift */; };
 		38F3B2EF25ED8E2A005C48AA /* TempTargetsStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38F3B2EE25ED8E2A005C48AA /* TempTargetsStorage.swift */; };
 		38FCF3D625E8FDF40078B0D1 /* MD5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38FCF3D525E8FDF40078B0D1 /* MD5.swift */; };
@@ -481,6 +482,7 @@
 		38E98A2F25F52FF700C0CED0 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
 		38E98A3625F5509500C0CED0 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
 		38EA05D9261F6E7C0064E39B /* SimpleLogReporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleLogReporter.swift; sourceTree = "<group>"; };
+		38EA05FF262091870064E39B /* BolusProgressViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusProgressViewStyle.swift; sourceTree = "<group>"; };
 		38F37827261260DC009DB701 /* Color+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Extensions.swift"; sourceTree = "<group>"; };
 		38F3783A2613555C009DB701 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
 		38F3B2EE25ED8E2A005C48AA /* TempTargetsStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempTargetsStorage.swift; sourceTree = "<group>"; };
@@ -1002,6 +1004,7 @@
 				3883581B25EE79BB00E024B2 /* DecimalTextField.swift */,
 				383420D825FFEB3F002D46C1 /* Popup.swift */,
 				389ECDFD2601061500D86C4F /* View+Snapshot.swift */,
+				38EA05FF262091870064E39B /* BolusProgressViewStyle.swift */,
 			);
 			path = Views;
 			sourceTree = "<group>";
@@ -1766,6 +1769,7 @@
 				2BE9A6FA20875F6F4F9CD461 /* PumpSettingsEditorProvider.swift in Sources */,
 				6B9625766B697D1C98E455A2 /* PumpSettingsEditorViewModel.swift in Sources */,
 				A0B8EC8CC5CD1DD237D1BCD2 /* PumpSettingsEditorRootView.swift in Sources */,
+				38EA0600262091870064E39B /* BolusProgressViewStyle.swift in Sources */,
 				389ECDFE2601061500D86C4F /* View+Snapshot.swift in Sources */,
 				38E98A3725F5509500C0CED0 /* String+Extensions.swift in Sources */,
 				1D086541F369D339A74893AC /* BasalProfileEditorBuilder.swift in Sources */,

+ 14 - 7
FreeAPS/Sources/APS/APSManager.swift

@@ -289,11 +289,10 @@ final class BaseAPSManager: APSManager, Injectable {
                     self.determineBasal().sink { _ in }.store(in: &self.lifetime)
                 }
             }
-
-            self.bolusReporter = pump.createBolusProgressReporter(reportingOn: self.processQueue)
-            self.bolusReporter?.addObserver(self)
-        } receiveValue: { _ in }
-            .store(in: &lifetime)
+        } receiveValue: { _ in
+            self.createBolusReporter()
+        }
+        .store(in: &lifetime)
     }
 
     func enactTempBasal(rate: Double, duration: TimeInterval) {
@@ -458,8 +457,11 @@ final class BaseAPSManager: APSManager, Injectable {
                 return Just(()).setFailureType(to: Error.self)
                     .eraseToAnyPublisher()
             }
-            return pump.enactBolus(units: Double(units), automatic: true).map { _ in () }
-                .eraseToAnyPublisher()
+            return pump.enactBolus(units: Double(units), automatic: true).map { _ in
+                self.createBolusReporter()
+                return ()
+            }
+            .eraseToAnyPublisher()
         }()
 
         basalPublisher
@@ -500,6 +502,11 @@ final class BaseAPSManager: APSManager, Injectable {
         debug(.apsManager, "\(error.localizedDescription)")
         lastError.send(error)
     }
+
+    private func createBolusReporter() {
+        bolusReporter = pumpManager?.createBolusProgressReporter(reportingOn: processQueue)
+        bolusReporter?.addObserver(self)
+    }
 }
 
 private extension PumpManager {

+ 4 - 2
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -85,7 +85,7 @@ extension Home {
         }
 
         var infoPanal: some View {
-            HStack(alignment: .firstTextBaseline) {
+            HStack(alignment: .center) {
                 if let tempRate = viewModel.tempRate {
                     Text((numberFormatter.string(from: tempRate as NSNumber) ?? "0") + " U/hr")
                         .font(.system(size: 12, weight: .bold)).foregroundColor(.insulin)
@@ -137,8 +137,10 @@ extension Home {
                 }
                 Spacer()
                 if let progress = viewModel.bolusProgress {
-                    Text("Bolus " + (numberFormatter.string(from: progress * 100 as NSNumber)!) + "%")
+                    Text("Bolusing")
                         .font(.system(size: 12, weight: .bold)).foregroundColor(.insulin)
+                    ProgressView(value: Double(progress))
+                        .progressViewStyle(BolusProgressViewStyle())
                         .padding(.trailing, 8)
                 }
             }

+ 20 - 0
FreeAPS/Sources/Views/BolusProgressViewStyle.swift

@@ -0,0 +1,20 @@
+import SwiftUI
+
+public struct BolusProgressViewStyle: ProgressViewStyle {
+    public func makeBody(configuration: LinearProgressViewStyle.Configuration) -> some View {
+        ZStack {
+            Circle()
+                .stroke(lineWidth: 6.0)
+                .opacity(0.3)
+                .foregroundColor(.secondary)
+                .frame(width: 16, height: 16)
+
+            Circle()
+                .trim(from: 0.0, to: CGFloat(configuration.fractionCompleted ?? 0))
+                .stroke(style: StrokeStyle(lineWidth: 6.0, lineCap: .round, lineJoin: .round))
+                .foregroundColor(.insulin)
+                .rotationEffect(Angle(degrees: -90))
+                .frame(width: 16, height: 16)
+        }.frame(width: 30, height: 30)
+    }
+}