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

Refactor Apple Health and Tidepool setting views

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

+ 1 - 1
FreeAPS/Sources/Modules/CalendarEventSettings/View/CalendarEventSettingsRootView.swift

@@ -59,7 +59,7 @@ extension CalendarEventSettings {
                                 ForEach(state.calendarIDs, id: \.self) {
                                     Text($0).tag($0)
                                 }
-                            }.padding(.vertical)
+                            }
                         }
                     }.listRowBackground(Color.chart)
 

+ 53 - 16
FreeAPS/Sources/Modules/HealthKit/View/AppleHealthKitRootView.swift

@@ -6,6 +6,13 @@ extension AppleHealthKit {
         let resolver: Resolver
         @StateObject var state = StateModel()
 
+        @State private var shouldDisplayHint: Bool = false
+        @State var hintDetent = PresentationDetent.large
+        @State var selectedVerboseHint: String?
+        @State var hintLabel: String?
+        @State private var decimalPlaceholder: Decimal = 0.0
+        @State private var booleanPlaceholder: Bool = false
+
         @Environment(\.colorScheme) var colorScheme
         var color: LinearGradient {
             colorScheme == .dark ? LinearGradient(
@@ -26,26 +33,56 @@ extension AppleHealthKit {
 
         var body: some View {
             Form {
-                Section {
-                    Toggle("Connect to Apple Health", isOn: $state.useAppleHealth)
-                    HStack {
-                        Image(systemName: "pencil.circle.fill")
-                        Text(
-                            "This allows Trio to read from and write to Apple Heath. You must also give permissions in Settings > Health > Data Access. If you enter a glucose value into Apple Health, open Trio to confirm it shows up."
-                        )
-                        .font(.caption)
-                    }
-                    .foregroundColor(Color.secondary)
-                    if state.needShowInformationTextForSetPermissions {
-                        HStack {
-                            Image(systemName: "exclamationmark.circle.fill")
-                            Text("For write data to Apple Health you must give permissions in Settings > Health > Data Access")
-                                .font(.caption)
+                SettingInputSection(
+                    decimalValue: $decimalPlaceholder,
+                    booleanValue: $state.useAppleHealth,
+                    shouldDisplayHint: $shouldDisplayHint,
+                    selectedVerboseHint: Binding(
+                        get: { selectedVerboseHint },
+                        set: {
+                            selectedVerboseHint = $0
+                            hintLabel = "Connect to Apple Health"
+                        }
+                    ),
+                    type: .boolean,
+                    label: "Connect to Apple Health",
+                    miniHint: "Allows Trio to read from and write to Apple Health.",
+                    verboseHint: NSLocalizedString(
+                        "This allows Trio to read from and write to Apple Health. You must also give permissions in iOS Settings > Health > Data Access. If you enter a glucose value into Apple Health, open Trio to confirm it shows up.",
+                        comment: "Suspend Zeros IOB"
+                    ),
+                    headerText: "Apple Health Integration"
+                )
+
+                if !state.needShowInformationTextForSetPermissions {
+                    Section {
+                        VStack {
+                            HStack {
+                                Image(systemName: "exclamationmark.circle.fill")
+                                Text("Give Apple Health Write Permissions")
+                            }.padding(.bottom)
+                            Text("""
+                            1. Open the Settings app on your iOS device.
+                            2. Scroll down and select "Health."
+                            3. Tap on "Data Access & Devices."
+                            4. Find and select "Trio" from the list of apps.
+                            5. Ensure that the "Write Data" option is enabled for the desired health metrics.
+                            """).font(.footnote)
                         }
+                        .padding(.vertical)
                         .foregroundColor(Color.secondary)
-                    }
+                    }.listRowBackground(Color.chart)
                 }
             }
+            .sheet(isPresented: $shouldDisplayHint) {
+                SettingInputHintView(
+                    hintDetent: $hintDetent,
+                    shouldDisplayHint: $shouldDisplayHint,
+                    hintLabel: hintLabel ?? "",
+                    hintText: selectedVerboseHint ?? "",
+                    sheetTitle: "Help"
+                )
+            }
             .scrollContentBackground(.hidden).background(color)
             .onAppear(perform: configureView)
             .navigationTitle("Apple Health")

+ 64 - 12
FreeAPS/Sources/Modules/Settings/View/TidepoolStartView.swift

@@ -4,23 +4,63 @@ import SwiftUI
 struct TidepoolStartView: View {
     @ObservedObject var state: Settings.StateModel
 
+    @State private var shouldDisplayHint: Bool = false
+    @State var hintDetent = PresentationDetent.large
+    @State private var decimalPlaceholder: Decimal = 0.0
+    @State private var booleanPlaceholder: Bool = false
+
+    @Environment(\.colorScheme) var colorScheme
+    var color: LinearGradient {
+        colorScheme == .dark ? LinearGradient(
+            gradient: Gradient(colors: [
+                Color.bgDarkBlue,
+                Color.bgDarkerDarkBlue
+            ]),
+            startPoint: .top,
+            endPoint: .bottom
+        )
+            :
+            LinearGradient(
+                gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
+                startPoint: .top,
+                endPoint: .bottom
+            )
+    }
+
     var body: some View {
         Form {
             Section(
-                header: Text("Connect to Tidepool"),
-                footer: VStack(alignment: .leading, spacing: 2) {
-                    Text(
-                        "When connected, uploading of carbs, bolus, basal and glucose from Trio to your Tidepool account is enabled."
-                    )
-                    Text(
-                        "\nUse your Tidepool credentials to login. If you dont already have a Tidepool account, you can sign up for one on the login page."
-                    )
-                }
-            )
+                header: Text("Tidepool Integration"),
+                content:
                 {
-                    Button("Connect to Tidepool") { state.setupTidepool = true }
+                    VStack {
+                        Button {
+                            state.setupTidepool.toggle()
+                        }
+                        label: { Text("Connect to Tidepool").font(.title3) }
+                            .frame(maxWidth: .infinity, alignment: .center)
+                            .buttonStyle(.bordered)
+
+                        HStack(alignment: .top) {
+                            Text("You can connect Trio to seamlessly upload and manage your diabetes data on Tidepool.")
+                                .font(.footnote)
+                                .foregroundColor(.secondary)
+                                .lineLimit(nil)
+                            Spacer()
+                            Button(
+                                action: {
+                                    shouldDisplayHint.toggle()
+                                },
+                                label: {
+                                    HStack {
+                                        Image(systemName: "questionmark.circle")
+                                    }
+                                }
+                            ).buttonStyle(BorderlessButtonStyle())
+                        }.padding(.top)
+                    }.padding(.vertical)
                 }
-                .navigationTitle("Tidepool")
+            ).listRowBackground(Color.chart)
         }
         .sheet(isPresented: $state.setupTidepool) {
             if let serviceUIType = state.serviceUIType,
@@ -42,5 +82,17 @@ struct TidepoolStartView: View {
                 }
             }
         }
+        .sheet(isPresented: $shouldDisplayHint) {
+            SettingInputHintView(
+                hintDetent: $hintDetent,
+                shouldDisplayHint: $shouldDisplayHint,
+                hintLabel: "Connect to Tidepool",
+                hintText: "When connected, uploading of carbs, bolus, basal and glucose from Trio to your Tidepool account is enabled.\n\nUse your Tidepool credentials to login. If you dont already have a Tidepool account, you can sign up for one on the login page.",
+                sheetTitle: "Help"
+            )
+        }
+        .scrollContentBackground(.hidden).background(color)
+        .navigationTitle("Tidepool")
+        .navigationBarTitleDisplayMode(.automatic)
     }
 }