Przeglądaj źródła

Enable pump addition from home view via confirmation dialog

Deniz Cengiz 1 rok temu
rodzic
commit
4a0e53ff6a

+ 6 - 21
FreeAPS/Sources/Modules/Home/HomeStateModel.swift

@@ -80,6 +80,7 @@ extension Home {
         @Published var pumpStatusHighlightMessage: String? = nil
         @Published var cgmAvailable: Bool = false
         @Published var showCarbsRequiredBadge: Bool = true
+        private(set) var setupPumpType: PumpConfig.PumpType = .minimed
 
         let context = CoreDataStack.shared.newTaskContext()
         let viewContext = CoreDataStack.shared.persistentContainer.viewContext
@@ -202,27 +203,6 @@ extension Home {
                     }
                 }
                 .store(in: &lifetime)
-
-            $setupPump
-                .sink { [weak self] show in
-                    guard let self = self else { return }
-                    if show, let pumpManager = self.provider.apsManager.pumpManager,
-                       let bluetoothProvider = self.provider.apsManager.bluetoothManager
-                    {
-                        let view = PumpConfig.PumpSettingsView(
-                            pumpManager: pumpManager,
-                            bluetoothManager: bluetoothProvider,
-                            completionDelegate: self,
-                            setupDelegate: self
-                        ).asAny()
-                        self.router.mainSecondaryModalView.send(view)
-                    } else if show {
-                        self.router.mainSecondaryModalView.send(self.router.view(for: .pumpConfigDirect))
-                    } else {
-                        self.router.mainSecondaryModalView.send(nil)
-                    }
-                }
-                .store(in: &lifetime)
         }
 
         private func registerHandlers() {
@@ -268,6 +248,11 @@ extension Home {
             }
         }
 
+        func addPump(_ type: PumpConfig.PumpType) {
+            setupPumpType = type
+            setupPump = true
+        }
+
         /// Display the eventual status message provided by the manager of the pump
         /// Only display if state is warning or critical message else return nil
         private func displayPumpStatusHighlightMessage(_ didDeactivate: Bool = false) {

+ 32 - 1
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -15,6 +15,7 @@ extension Home {
         @State var showTreatments = false
         @State var selectedTab: Int = 0
         @State private var statusTitle: String = ""
+        @State var showPumpSelection: Bool = false
 
         struct Buttons: Identifiable {
             let label: String
@@ -165,7 +166,13 @@ extension Home {
                 pumpStatusHighlightMessage: $state.pumpStatusHighlightMessage,
                 battery: $state.batteryFromPersistence
             ).onTapGesture {
-                state.setupPump = true
+                if state.pumpDisplayState == nil {
+                    // shows user confirmation dialog with pump model choices, then proceeds to setup
+                    showPumpSelection.toggle()
+                } else {
+                    // sends user to pump settings
+                    state.setupPump.toggle()
+                }
             }
         }
 
@@ -754,6 +761,30 @@ extension Home {
                             }
                     )
             }
+            .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
+                Button("Medtronic") { state.addPump(.minimed) }
+                Button("Omnipod Eros") { state.addPump(.omnipod) }
+                Button("Omnipod Dash") { state.addPump(.omnipodBLE) }
+                Button("Pump Simulator") { state.addPump(.simulator) }
+            } message: { Text("Select Pump Model") }
+            .sheet(isPresented: $state.setupPump) {
+                if let pumpManager = state.provider.apsManager.pumpManager {
+                    PumpConfig.PumpSettingsView(
+                        pumpManager: pumpManager,
+                        bluetoothManager: state.provider.apsManager.bluetoothManager!,
+                        completionDelegate: state,
+                        setupDelegate: state
+                    )
+                } else {
+                    PumpConfig.PumpSetupView(
+                        pumpType: state.setupPumpType,
+                        pumpInitialSettings: PumpConfig.PumpInitialSettings.default,
+                        bluetoothManager: state.provider.apsManager.bluetoothManager!,
+                        completionDelegate: state,
+                        setupDelegate: state
+                    )
+                }
+            }
             .sheet(isPresented: $state.isLegendPresented) {
                 NavigationStack {
                     Text(

+ 1 - 6
FreeAPS/Sources/Modules/PumpConfig/PumpConfigStateModel.swift

@@ -39,8 +39,8 @@ extension PumpConfig {
         }
 
         func addPump(_ type: PumpType) {
-            setupPump = true
             setupPumpType = type
+            setupPump = true
         }
 
         func ack() {
@@ -70,9 +70,4 @@ extension PumpConfig.StateModel: PumpManagerOnboardingDelegate {
     func pumpManagerOnboarding(didPauseOnboarding _: PumpManagerUI) {
         // TODO:
     }
-
-//    func pumpManagerSetupViewController(_: PumpManagerSetupViewController, didSetUpPumpManager pumpManager: PumpManagerUI) {
-//        provider.setPumpManager(pumpManager)
-//        setupPump = false
-//    }
 }

+ 1 - 1
FreeAPS/Sources/Modules/PumpSettingsEditor/View/PumpSettingsEditorRootView.swift

@@ -107,7 +107,7 @@ extension PumpSettingsEditor {
                             impactHeavy.impactOccurred()
                             state.save()
                         } label: {
-                            Text(state.syncInProgress ? "Saving..." : "Save on Pump")
+                            Text(state.syncInProgress ? "Saving..." : "Save")
                         }
                         .disabled(state.syncInProgress || !state.hasChanged)
                         .frame(maxWidth: .infinity, alignment: .center)

+ 21 - 4
FreeAPS/Sources/Modules/Settings/SettingItems.swift

@@ -277,14 +277,21 @@ enum SettingItems {
     static func filteredItems(searchText: String) -> [FilteredSettingItem] {
         allItems.flatMap { item in
             var results = [FilteredSettingItem]()
-            if item.title.stringValue.localizedCaseInsensitiveContains(searchText) {
+            let searchTextToLower = searchText.lowercased()
+
+            if item.title.stringValue.localizedCaseInsensitiveContains(searchTextToLower) ||
+                item.title.englishValue.localizedCaseInsensitiveContains(searchTextToLower)
+            {
                 results.append(FilteredSettingItem(settingItem: item, matchedContent: item.title))
             }
-            if let matchedContents = item.searchContents?
-                .filter({ $0.stringValue.localizedCaseInsensitiveContains(searchText) })
-            {
+
+            if let matchedContents = item.searchContents?.filter({
+                $0.stringValue.localizedCaseInsensitiveContains(searchTextToLower) ||
+                    $0.englishValue.localizedCaseInsensitiveContains(searchTextToLower)
+            }) {
                 results.append(contentsOf: matchedContents.map { FilteredSettingItem(settingItem: item, matchedContent: $0) })
             }
+
             return results
         }
     }
@@ -300,4 +307,14 @@ extension LocalizedStringKey {
             return ""
         }
     }
+
+    var englishValue: String {
+        let mirror = Mirror(reflecting: self)
+        let children = mirror.children
+        if let label = children.first(where: { $0.label == "key" })?.value as? String {
+            return Bundle.main.localizedString(forKey: label, value: nil, table: nil)
+        } else {
+            return ""
+        }
+    }
 }