Просмотр исходного кода

Fix handling again; use filtered steps items and computed vars

Deniz Cengiz 1 год назад
Родитель
Сommit
e43a27c0b8

+ 13 - 0
Trio/Sources/Modules/Onboarding/OnboardingStateModel.swift

@@ -106,9 +106,20 @@ extension Onboarding {
 
         var hasReadAlgorithmSetupInformation: Bool = false
 
+        // Autosens Settings
         var autosensMin: Decimal = 0.7
         var autosensMax: Decimal = 1.2
         var rewindResetsAutosens: Bool = true
+
+        var filteredAutosensSettingsSubsteps: [AutosensSettingsSubstep] {
+            if pumpOptionForOnboardingUnits == .minimed || pumpOptionForOnboardingUnits == .dana {
+                return AutosensSettingsSubstep.allCases
+            } else {
+                return [AutosensSettingsSubstep.autosensMin, AutosensSettingsSubstep.autosensMax]
+            }
+        }
+
+        // SMB Settings
         var enableSMBAlways: Bool = false
         var enableSMBWithCOB: Bool = false
         var enableSMBWithTempTarget: Bool = false
@@ -120,6 +131,8 @@ extension Onboarding {
         var maxSMBMinutes: Decimal = 30
         var maxUAMMinutes: Decimal = 30
         var maxDeltaGlucoseThreshold: Decimal = 0.2
+
+        // Target Behavior
         var highTempTargetRaisesSensitivity: Bool = false
         var lowTempTargetLowersSensitivity: Bool = false
         var sensitivityRaisesTarget: Bool = false

+ 22 - 22
Trio/Sources/Modules/Onboarding/View/OnboardingRootView.swift

@@ -80,7 +80,7 @@ extension Onboarding {
                                 stepsWithSubsteps: [
                                     .nightscout: NightscoutSubstep.allCases.count,
                                     .deliveryLimits: DeliveryLimitSubstep.allCases.count,
-                                    .autosensSettings: AutosensSettingsSubstep.allCases.count,
+                                    .autosensSettings: state.filteredAutosensSettingsSubsteps.count,
                                     .smbSettings: SMBSettingsSubstep.allCases.count,
                                     .targetBehavior: TargetBehaviorSubstep.allCases.count
                                 ],
@@ -431,18 +431,14 @@ struct OnboardingNavigationButtons: View {
             }
 
         case .autosensSettings:
-            if let previous = AutosensSettingsSubstep(rawValue: currentAutosensSubstep.rawValue - 1) {
-                currentAutosensSubstep = previous
+            let steps = state.filteredAutosensSettingsSubsteps
+            if let current = steps.firstIndex(of: currentAutosensSubstep),
+               current > 0
+            {
+                currentAutosensSubstep = steps[current - 1]
             } else if let previousStep = currentStep.previous {
                 currentStep = previousStep
-                currentAutosensSubstep = .autosensMin
-
-                /// Skip Autosens substep `.rewindResetsAutosens` if pump model is not `.minimed`.
-                if state.pumpOptionForOnboardingUnits == .minimed || state.pumpOptionForOnboardingUnits == .dana {
-                    currentAutosensSubstep = .rewindResetsAutosens
-                } else {
-                    currentAutosensSubstep = .autosensMax
-                }
+                currentAutosensSubstep = steps.first ?? .autosensMin
             }
 
         case .smbSettings:
@@ -458,6 +454,15 @@ struct OnboardingNavigationButtons: View {
             } else if let previousStep = currentStep.previous {
                 currentStep = previousStep
                 currentSMBSubstep = .enableSMBAlways
+
+                switch state.pumpOptionForOnboardingUnits {
+                case .dana,
+                     .minimed:
+                    currentAutosensSubstep = .rewindResetsAutosens
+                case .omnipodDash,
+                     .omnipodEros:
+                    currentAutosensSubstep = .autosensMax
+                }
             }
 
         case .targetBehavior:
@@ -507,19 +512,14 @@ struct OnboardingNavigationButtons: View {
             }
 
         case .autosensSettings:
-            if let next = AutosensSettingsSubstep(rawValue: currentAutosensSubstep.rawValue + 1) {
-                /// Skip Autosens substep `.rewindResetsAutosens` if pump model is not `.minimed`.
-                if currentAutosensSubstep == .autosensMax,
-                   state.pumpOptionForOnboardingUnits != .minimed || state.pumpOptionForOnboardingUnits != .dana,
-                   let nextMainStep = currentStep.next
-                {
-                    currentStep = nextMainStep
-                } else {
-                    currentAutosensSubstep = next
-                }
+            let steps = state.filteredAutosensSettingsSubsteps
+            if let current = steps.firstIndex(of: currentAutosensSubstep),
+               current + 1 < steps.count
+            {
+                currentAutosensSubstep = steps[current + 1]
             } else if let nextStep = currentStep.next {
                 currentStep = nextStep
-                currentAutosensSubstep = .autosensMin
+                currentAutosensSubstep = steps.first ?? .autosensMin
             }
 
         case .smbSettings:

+ 12 - 1
Trio/Sources/Modules/Onboarding/View/OnboardingSteps/AlgorithmSettings/AlgorithmSettingsSubstepView.swift

@@ -16,6 +16,17 @@ struct AlgorithmSettingsSubstepView<Substep: AlgorithmSubstepProtocol & RawRepre
 
     private let settingsProvider = PickerSettingsProvider.shared
 
+    private var shouldDisableRewindResetsAutosens: Bool {
+        switch state.pumpOptionForOnboardingUnits {
+        case .dana,
+             .minimed:
+            return false
+        case .omnipodDash,
+             .omnipodEros:
+            return true
+        }
+    }
+
     var body: some View {
         VStack(alignment: .leading, spacing: 16) {
             Text(substep.title)
@@ -56,7 +67,7 @@ struct AlgorithmSettingsSubstepView<Substep: AlgorithmSubstepProtocol & RawRepre
                         decimalValue: $decimalPlaceholder,
                         booleanValue: $state.rewindResetsAutosens,
                         type: OnboardingInputSectionType.boolean,
-                        disabled: state.pumpOptionForOnboardingUnits != .minimed
+                        disabled: shouldDisableRewindResetsAutosens
                     )
                 case .enableSMBAlways:
                     algorithmSettingsInput(