AppleHealthKitRootView.swift 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import SwiftUI
  2. import Swinject
  3. extension AppleHealthKit {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @State private var shouldDisplayHint: Bool = false
  8. @State var hintDetent = PresentationDetent.large
  9. @State var selectedVerboseHint: String?
  10. @State var hintLabel: String?
  11. @State private var decimalPlaceholder: Decimal = 0.0
  12. @State private var booleanPlaceholder: Bool = false
  13. @Environment(\.colorScheme) var colorScheme
  14. var color: LinearGradient {
  15. colorScheme == .dark ? LinearGradient(
  16. gradient: Gradient(colors: [
  17. Color.bgDarkBlue,
  18. Color.bgDarkerDarkBlue
  19. ]),
  20. startPoint: .top,
  21. endPoint: .bottom
  22. )
  23. :
  24. LinearGradient(
  25. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  26. startPoint: .top,
  27. endPoint: .bottom
  28. )
  29. }
  30. var body: some View {
  31. Form {
  32. SettingInputSection(
  33. decimalValue: $decimalPlaceholder,
  34. booleanValue: $state.useAppleHealth,
  35. shouldDisplayHint: $shouldDisplayHint,
  36. selectedVerboseHint: Binding(
  37. get: { selectedVerboseHint },
  38. set: {
  39. selectedVerboseHint = $0
  40. hintLabel = "Connect to Apple Health"
  41. }
  42. ),
  43. units: state.units,
  44. type: .boolean,
  45. label: "Connect to Apple Health",
  46. miniHint: "Allows Trio to read from and write to Apple Health.",
  47. verboseHint: NSLocalizedString(
  48. "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.",
  49. comment: "Suspend Zeros IOB"
  50. ),
  51. headerText: "Apple Health Integration"
  52. )
  53. if !state.needShowInformationTextForSetPermissions {
  54. Section {
  55. VStack {
  56. HStack {
  57. Image(systemName: "exclamationmark.circle.fill")
  58. Text("Give Apple Health Write Permissions")
  59. }.padding(.bottom)
  60. Text("""
  61. 1. Open the Settings app on your iOS device.
  62. 2. Scroll down and select "Health."
  63. 3. Tap on "Data Access & Devices."
  64. 4. Find and select "Trio" from the list of apps.
  65. 5. Ensure that the "Write Data" option is enabled for the desired health metrics.
  66. """).font(.footnote)
  67. }
  68. .padding(.vertical)
  69. .foregroundColor(Color.secondary)
  70. }.listRowBackground(Color.chart)
  71. }
  72. }
  73. .sheet(isPresented: $shouldDisplayHint) {
  74. SettingInputHintView(
  75. hintDetent: $hintDetent,
  76. shouldDisplayHint: $shouldDisplayHint,
  77. hintLabel: hintLabel ?? "",
  78. hintText: selectedVerboseHint ?? "",
  79. sheetTitle: "Help"
  80. )
  81. }
  82. .scrollContentBackground(.hidden).background(color)
  83. .onAppear(perform: configureView)
  84. .navigationTitle("Apple Health")
  85. .navigationBarTitleDisplayMode(.automatic)
  86. }
  87. }
  88. }