Prechádzať zdrojové kódy

Basic setup of import handling (import still TODO) WIP

Deniz Cengiz 1 rok pred
rodič
commit
af8cae48c9

+ 10 - 7
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -39137,9 +39137,6 @@
         }
       }
     },
-    "Before you proceed, please decide if you want to import existing therapy settings from Nightscout (your \"default profile\"), or if you would like to start from scratch." : {
-
-    },
     "Beta (TestFlight) Expires" : {
       "localizations" : {
         "bg" : {
@@ -51502,6 +51499,9 @@
         }
       }
     },
+    "Configure Yourself" : {
+
+    },
     "Confirm" : {
       "localizations" : {
         "bg" : {
@@ -52313,6 +52313,9 @@
         }
       }
     },
+    "Connected" : {
+
+    },
     "Connected Services" : {
       "localizations" : {
         "bg" : {
@@ -134765,6 +134768,9 @@
     "Please choose from the options below." : {
 
     },
+    "Please choose if you want to import existing therapy settings from Nightscout or start from scratch." : {
+
+    },
     "Please enter your credentials:" : {
 
     },
@@ -163467,9 +163473,6 @@
         }
       }
     },
-    "Tap \"Import Settings\" to begin, or \"Next\" to skip." : {
-
-    },
     "Tap and hold a bar to reveal more details." : {
 
     },
@@ -183984,7 +183987,7 @@
         }
       }
     },
-    "Trio will import the following therapy settings from Nightscout:" : {
+    "Trio will import the following therapy settings from your Nightscout instance:" : {
 
     },
     "Trio will use the larger of the default setting calculation below and the value entered here." : {

+ 4 - 1
Trio/Sources/Modules/Onboarding/OnboardingStateModel.swift

@@ -17,11 +17,13 @@ extension Onboarding {
 
         // Nightscout Setup
         var nightscoutSetupOption: NightscoutSetupOption = .noSelection
+        var nightscoutImportOption: NightscoutImportOption = .noSelection
         var url = ""
         var secret = ""
         var message = ""
         var isValidURL: Bool = false
-        var connecting = false
+        var connecting: Bool = false
+        var isConnectedToNS: Bool = false
 
         // Carb Ratio related
         var carbRatioItems: [CarbRatioEditor.Item] = []
@@ -272,6 +274,7 @@ extension Onboarding.StateModel {
             } receiveValue: {
                 self.keychain.setValue(self.url, forKey: NightscoutConfig.Config.urlKey)
                 self.keychain.setValue(self.secret, forKey: NightscoutConfig.Config.secretKey)
+                self.isConnectedToNS = true
             }
             .store(in: &lifetime)
     }

+ 24 - 19
Trio/Sources/Modules/Onboarding/View/OnboardingSteps/Nightscout/NightscoutImportStepView.swift

@@ -4,40 +4,45 @@ struct NightscoutImportStepView: View {
     @Bindable var state: Onboarding.StateModel
 
     var body: some View {
-        VStack(alignment: .leading, spacing: 8) {
+        VStack(alignment: .leading, spacing: 20) {
             Text(
-                "Before you proceed, please decide if you want to import existing therapy settings from Nightscout (your \"default profile\"), or if you would like to start from scratch."
-            )
+                "Please choose if you want to import existing therapy settings from Nightscout or start from scratch."
+            ).font(.headline)
+                .padding(.horizontal)
 
-            Text("Tap \"Import Settings\" to begin, or \"Next\" to skip.")
-                .foregroundStyle(Color.secondary)
+            ForEach([NightscoutImportOption.useImport, NightscoutImportOption.skipImport], id: \.self) { option in
+                Button(action: {
+                    state.nightscoutImportOption = option
+                }) {
+                    HStack {
+                        Image(systemName: state.nightscoutImportOption == option ? "largecircle.fill.circle" : "circle")
+                            .foregroundColor(state.nightscoutImportOption == option ? .accentColor : .secondary)
+                            .imageScale(.large)
 
-            Button(action: {
-                let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
-                impactHeavy.impactOccurred()
+                        Text(option.displayName)
+                            .foregroundColor(.primary)
 
-                // TODO: handle import
-            }) {
-                HStack {
-                    Text("Import Settings").bold()
+                        Spacer()
+                    }
+                    .padding()
+                    .background(Color.chart.opacity(0.45))
+                    .cornerRadius(10)
                 }
-                .frame(maxWidth: .infinity, alignment: .center)
-                .padding(.vertical, 8)
+                .buttonStyle(.plain)
             }
-            .disabled(state.url.isEmpty || state.secret.isEmpty)
-            .buttonStyle(.borderedProminent)
 
             VStack(alignment: .leading, spacing: 10) {
                 Text(
-                    "Trio will import the following therapy settings from Nightscout:"
+                    "Trio will import the following therapy settings from your Nightscout instance:"
                 )
                 VStack(alignment: .leading) {
+                    Text("• Glucose Targets")
                     Text("• Basal Rates")
-                    Text("• Insulin Sensitivities")
                     Text("• Carb Ratios")
-                    Text("• Glucose Targets")
+                    Text("• Insulin Sensitivities")
                 }
             }
+            .padding(.horizontal)
             .font(.footnote)
             .foregroundStyle(Color.secondary)
         }

+ 22 - 9
Trio/Sources/Modules/Onboarding/View/OnboardingSteps/Nightscout/NightscoutLoginStepView.swift

@@ -35,14 +35,6 @@ struct NightscoutLoginStepView: View {
 
             Spacer(minLength: 10)
 
-            if state.message.isNotEmpty {
-                VStack(alignment: .center) {
-                    Text(state.message)
-                        .font(.subheadline)
-                        .foregroundStyle(Color.orange)
-                }
-            }
-
             Button(action: {
                 let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
                 impactHeavy.impactOccurred()
@@ -58,8 +50,29 @@ struct NightscoutLoginStepView: View {
                 .frame(maxWidth: .infinity, alignment: .center)
                 .padding(.vertical, 8)
             }
-            .disabled(state.url.isEmpty || state.secret.isEmpty)
+            .disabled(state.isConnectedToNS || state.url.isEmpty || state.secret.isEmpty)
             .buttonStyle(.borderedProminent)
+
+            if state.message.isNotEmpty {
+                VStack(alignment: .center) {
+                    Text(state.message)
+                        .font(.subheadline)
+                        .foregroundStyle(Color.orange)
+                }
+            } else if state.isConnectedToNS {
+                HStack {
+                    Spacer()
+                    Text("Connected")
+                        .font(.subheadline)
+                        .foregroundColor(.green)
+                    ZStack {
+                        Image(systemName: "network")
+                        Image(systemName: "checkmark.circle.fill").foregroundColor(.green).font(.caption2)
+                            .offset(x: 9, y: 6)
+                    }
+                    Spacer()
+                }
+            }
         }
     }
 }

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

@@ -244,6 +244,25 @@ enum NightscoutSetupOption: String, Equatable, CaseIterable, Identifiable {
     }
 }
 
+enum NightscoutImportOption: String, Equatable, CaseIterable, Identifiable {
+    case useImport
+    case skipImport
+    case noSelection
+
+    var id: String { rawValue }
+
+    var displayName: String {
+        switch self {
+        case .useImport:
+            return String(localized: "Import Settings")
+        case .skipImport:
+            return String(localized: "Configure Yourself")
+        case .noSelection:
+            return ""
+        }
+    }
+}
+
 enum NightscoutSubstep: Int, CaseIterable, Identifiable {
     case setupSelection
     case connectToNightscout

+ 12 - 18
Trio/Sources/Modules/Onboarding/View/OnboardingView.swift

@@ -17,14 +17,16 @@ extension Onboarding {
         @State private var isAnimating = false
 
         private var shouldDisableNextButton: Bool {
-            (
-                currentStep == .nightscout && currentNightscoutSubstep == .setupSelection && state
-                    .nightscoutSetupOption == .noSelection
-            ) ||
+            currentStep == .nightscout &&
                 (
-                    currentStep == .nightscout && currentNightscoutSubstep == .connectToNightscout && state.url.isEmpty && !state
+                    currentNightscoutSubstep == .setupSelection && state
+                        .nightscoutSetupOption == .noSelection
+                ) ||
+                (
+                    currentNightscoutSubstep == .connectToNightscout && state.url.isEmpty && !state
                         .isValidURL && state.secret.isEmpty
                 )
+                || (currentNightscoutSubstep == .importFromNightscout && state.nightscoutImportOption == .noSelection)
         }
 
         var body: some View {
@@ -172,19 +174,7 @@ extension Onboarding {
                                                         .rawValue - 1
                                                 )!
                                             }
-                                        }
-
-//                                        else if currentStep == .nightscout {
-//                                            if currentNightscoutSubstep != .setupSelection,
-//                                               state.nightscoutSetupOption == .skipNightscoutSetup
-//                                            {
-//                                                currentNightscoutSubstep = .setupSelection
-//                                            } else {
-//                                                currentNightscoutSubstep =
-//                                                    NightscoutSubstep(rawValue: currentNightscoutSubstep.rawValue - 1)!
-//                                            }
-//                                        }
-                                        else if currentStep == .deliveryLimits {
+                                        } else if currentStep == .deliveryLimits {
                                             if let previousSub = DeliveryLimitSubstep(
                                                 rawValue: currentDeliverySubstep
                                                     .rawValue - 1
@@ -231,6 +221,10 @@ extension Onboarding {
                                                         .rawValue + 1
                                                 )!
                                             }
+                                        } else if currentNightscoutSubstep == .importFromNightscout,
+                                                  state.nightscoutImportOption == .useImport
+                                        {
+                                            // TODO: trigger import, show animation, then proceed to next step
                                         } else if let next = currentStep.next {
                                             currentStep = next
                                         }