Преглед изворни кода

Fix navigation issue; small refactor for conciseness

Deniz Cengiz пре 1 година
родитељ
комит
64b1e16556

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

@@ -148,29 +148,32 @@ struct OnboardingProgressBar: View {
     let stepsWithSubsteps: [OnboardingStep: Int]
     let nightscoutSetupOption: NightscoutSetupOption
 
+    private let capsuleSize = CGFloat(UIFont.preferredFont(forTextStyle: .subheadline).pointSize) * 1.3
+
     var body: some View {
-        HStack(spacing: 4) {
-            ForEach(renderedSteps, id: \.id) { step in
-                ZStack(alignment: .leading) {
-                    Rectangle()
-                        .fill(Color.gray.opacity(0.3))
-                        .frame(height: 4)
-                        .cornerRadius(2)
-
-                    GeometryReader { geo in
+        VStack(alignment: .leading, spacing: 10) {
+            HStack(spacing: 4) {
+                ForEach(renderedSteps, id: \.id) { step in
+                    ZStack(alignment: .leading) {
                         Rectangle()
-                            .fill(Color.blue)
-                            .frame(
-                                width: geo.size.width * fillFraction(for: step.step, totalSubsteps: step.substeps),
-                                height: 4
-                            )
+                            .fill(Color.gray.opacity(0.3))
+                            .frame(height: 4)
                             .cornerRadius(2)
+
+                        GeometryReader { geo in
+                            Rectangle()
+                                .fill(Color.blue)
+                                .frame(
+                                    width: geo.size.width * fillFraction(for: step.step, totalSubsteps: step.substeps),
+                                    height: 4
+                                )
+                                .cornerRadius(2)
+                        }
                     }
+                    .frame(height: 4)
                 }
-                .frame(height: 4)
             }
-        }
-        .padding(.horizontal)
+        }.padding(.horizontal)
     }
 
     private var renderedSteps: [(id: String, step: OnboardingStep, substeps: Int?)] {
@@ -267,7 +270,7 @@ struct OnboardingStepContent: View {
                                     .fixedSize(horizontal: false, vertical: true)
                             }
                         }
-                        .padding([.horizontal, .top])
+                        .padding(.horizontal)
                     }
 
                     Group {
@@ -401,10 +404,6 @@ struct OnboardingNavigationButtons: View {
 
     private func handleBackNavigation() {
         switch currentStep {
-        case .completed:
-            currentStep = .targetBehavior
-            currentTargetBehaviorSubstep = .halfBasalTarget
-
         case .nightscout:
             if currentNightscoutSubstep == .setupSelection,
                let previous = currentStep.previous
@@ -474,6 +473,16 @@ struct OnboardingNavigationButtons: View {
                 currentSMBSubstep = .maxDeltaGlucoseThreshold
             }
 
+        case .notifications:
+            currentTargetBehaviorSubstep = .halfBasalTarget
+
+            if let previous = currentStep.previous {
+                currentStep = previous
+            }
+
+        case .completed:
+            currentStep = .bluetooth
+
         default:
             if let previous = currentStep.previous {
                 currentStep = previous

+ 9 - 41
Trio/Sources/Modules/Onboarding/View/OnboardingSteps/CompletedStepView.swift

@@ -20,49 +20,17 @@ struct CompletedStepView: View {
             .foregroundColor(.secondary)
 
             VStack(alignment: .leading, spacing: 12) {
-                completedItemsView(
-                    stepIndex: 1,
-                    title: String(localized: "Prepare Trio"),
-                    description: String(
-                        localized: "App diagnostics sharing, Nightscout setup, and unit and pump model selection are all complete."
+                ForEach(Array(OnboardingChapter.allCases.enumerated()), id: \.element.id) { index, chapter in
+                    completedItemsView(
+                        stepIndex: index + 1,
+                        title: chapter.title,
+                        description: chapter.completedDescription
                     )
-                )
 
-                Divider()
-
-                completedItemsView(
-                    stepIndex: 2,
-                    title: String(localized: "Therapy Settings"),
-                    description: String(
-                        localized: "Glucose target, basal rates, carb ratios, and insulin sensitivity match your needs."
-                    )
-                )
-
-                Divider()
-
-                completedItemsView(
-                    stepIndex: 3,
-                    title: String(localized: "Delivery Limits"),
-                    description: String(
-                        localized: "Safety boundaries for insulin delivery and carb entries are set to help Trio keep you safe."
-                    )
-                )
-
-                Divider()
-
-                completedItemsView(
-                    stepIndex: 4,
-                    title: String(localized: "Algorithm Settings"),
-                    description: String(localized: "Trio’s algorithm features are customized to fit your preferences and needs.")
-                )
-
-                Divider()
-
-                completedItemsView(
-                    stepIndex: 5,
-                    title: String(localized: "Permission Requests"),
-                    description: String(localized: "Notifications and Bluetooth permissions are handled to your liking.")
-                )
+                    if index < OnboardingChapter.allCases.count {
+                        Divider()
+                    }
+                }
             }
             .padding()
             .background(Color.green.opacity(0.1))

+ 10 - 50
Trio/Sources/Modules/Onboarding/View/OnboardingSteps/OverviewStepView.swift

@@ -14,58 +14,18 @@ struct OverviewStepView: View {
                 .padding(.horizontal)
 
             VStack(alignment: .center, spacing: 12) {
-                overviewItem(
-                    stepIndex: 1,
-                    title: String(localized: "Prepare Trio"),
-                    duration: "3-5",
-                    description: String(
-                        localized: "Configure diagnostics sharing, optionally sync with Nightscout, and enter essentials."
+                ForEach(Array(OnboardingChapter.allCases.enumerated()), id: \.element.id) { index, chapter in
+                    overviewItem(
+                        stepIndex: index + 1,
+                        title: chapter.title,
+                        duration: chapter.duration,
+                        description: chapter.overviewDescription
                     )
-                )
 
-                Divider()
-
-                overviewItem(
-                    stepIndex: 2,
-                    title: String(localized: "Therapy Settings"),
-                    duration: "5-10",
-                    description: String(
-                        localized: "Define your glucose targets, basal rates, carb ratios, and insulin sensitivities."
-                    )
-                )
-
-                Divider()
-
-                overviewItem(
-                    stepIndex: 3,
-                    title: String(localized: "Delivery Limits"),
-                    duration: "3-5",
-                    description: String(
-                        localized: "Set boundaries for insulin delivery and carb entries to help Trio keep you safe."
-                    )
-                )
-
-                Divider()
-
-                overviewItem(
-                    stepIndex: 4,
-                    title: String(localized: "Algorithm Settings"),
-                    duration: "5-10",
-                    description: String(
-                        localized: "Customize Trio’s algorithm features. Most users start with the recommended settings."
-                    )
-                )
-
-                Divider()
-
-                overviewItem(
-                    stepIndex: 5,
-                    title: String(localized: "Permission Requests"),
-                    duration: "1",
-                    description: String(
-                        localized: "Authorize Trio to send notifications and use Bluetooth. You must allow both for Trio to work properly."
-                    )
-                )
+                    if index < OnboardingChapter.allCases.count {
+                        Divider()
+                    }
+                }
             }
             .padding()
             .background(Color.chart.opacity(0.65))

+ 86 - 0
Trio/Sources/Modules/Onboarding/View/OnboardingView+Util.swift

@@ -6,6 +6,92 @@ enum OnboardingNavigationDirection {
     case backward
 }
 
+enum OnboardingChapter: Int, CaseIterable {
+    case prepareTrio
+    case therapySettings
+    case deliveryLimits
+    case algorithmSettings
+    case permissionRequests
+
+    var id: Int { rawValue }
+
+    var title: String {
+        switch self {
+        case .prepareTrio:
+            return String(localized: "Prepare Trio")
+        case .therapySettings:
+            return String(localized: "Therapy Settings")
+        case .deliveryLimits:
+            return String(localized: "Delivery Limits")
+        case .algorithmSettings:
+            return String(localized: "Algorithm Settings")
+        case .permissionRequests:
+            return String(localized: "Permission Requests")
+        }
+    }
+
+    var overviewDescription: String {
+        switch self {
+        case .prepareTrio:
+            return String(
+                localized: "Configure diagnostics sharing, optionally sync with Nightscout, and enter essentials."
+            )
+        case .therapySettings:
+            return String(
+                localized: "Define your glucose targets, basal rates, carb ratios, and insulin sensitivities."
+            )
+        case .deliveryLimits:
+            return String(
+                localized: "Set boundaries for insulin delivery and carb entries to help Trio keep you safe."
+            )
+        case .algorithmSettings:
+            return String(
+                localized: "Customize Trio’s algorithm features. Most users start with the recommended settings."
+            )
+        case .permissionRequests:
+            return String(
+                localized: "Authorize Trio to send notifications and use Bluetooth. You must allow both for Trio to work properly."
+            )
+        }
+    }
+
+    var duration: String {
+        switch self {
+        case .prepareTrio:
+            return "3-5"
+        case .therapySettings:
+            return "5-10"
+        case .deliveryLimits:
+            return "3-5"
+        case .algorithmSettings:
+            return "5-10"
+        case .permissionRequests:
+            return "1"
+        }
+    }
+
+    var completedDescription: String {
+        switch self {
+        case .prepareTrio:
+            return String(
+                localized: "App diagnostics sharing, Nightscout setup, and unit and pump model selection are all complete."
+            )
+        case .therapySettings:
+            return String(
+                localized: "Glucose target, basal rates, carb ratios, and insulin sensitivity match your needs."
+            )
+        case .deliveryLimits:
+            return String(
+                localized: "Safety boundaries for insulin delivery and carb entries are set to help Trio keep you safe."
+            )
+        case .algorithmSettings:
+            return String(localized: "Trio’s algorithm features are customized to fit your preferences and needs.")
+        case .permissionRequests:
+            return String(localized: "Notifications and Bluetooth permissions are handled to your liking.")
+        }
+    }
+}
+
 /// Represents the different steps in the onboarding process.
 enum OnboardingStep: Int, CaseIterable, Identifiable, Equatable {
     case welcome