WatchConfigAppleWatchView.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import SwiftUI
  2. struct WatchConfigAppleWatchView: View {
  3. @ObservedObject var state: WatchConfig.StateModel
  4. @State private var shouldDisplayHint: Bool = false
  5. @State var hintDetent = PresentationDetent.large
  6. @State var selectedVerboseHint: AnyView?
  7. @State var hintLabel: String?
  8. @State private var decimalPlaceholder: Decimal = 0.0
  9. @State private var booleanPlaceholder: Bool = false
  10. @Environment(\.colorScheme) var colorScheme
  11. @Environment(AppState.self) var appState
  12. private func onDelete(offsets: IndexSet) {
  13. state.devices.remove(atOffsets: offsets)
  14. state.deleteGarminDevice()
  15. }
  16. var body: some View {
  17. List {
  18. Section(
  19. header: Text("Apple Watch Configuration"),
  20. content: {
  21. VStack {
  22. Picker(
  23. selection: $state.selectedAwConfig,
  24. label: Text("Display on Watch")
  25. ) {
  26. ForEach(AwConfig.allCases) { selection in
  27. Text(selection.displayName).tag(selection)
  28. }
  29. }.padding(.top)
  30. HStack(alignment: .center) {
  31. Text(
  32. "Select the information to display."
  33. )
  34. .font(.footnote)
  35. .foregroundColor(.secondary)
  36. .lineLimit(nil)
  37. Spacer()
  38. Button(
  39. action: {
  40. hintLabel = "Display on Watch"
  41. selectedVerboseHint =
  42. AnyView(VStack(alignment: .leading, spacing: 5) {
  43. Text("Choose between the following:")
  44. Text("• Heart Rate")
  45. Text("• Glucose Target")
  46. Text("• Steps")
  47. Text("• ISF")
  48. Text("• % Override")
  49. })
  50. shouldDisplayHint.toggle()
  51. },
  52. label: {
  53. HStack {
  54. Image(systemName: "questionmark.circle")
  55. }
  56. }
  57. ).buttonStyle(BorderlessButtonStyle())
  58. }.padding(.top)
  59. }.padding(.bottom)
  60. }
  61. ).listRowBackground(Color.chart)
  62. SettingInputSection(
  63. decimalValue: $decimalPlaceholder,
  64. booleanValue: $state.displayFatAndProteinOnWatch,
  65. shouldDisplayHint: $shouldDisplayHint,
  66. selectedVerboseHint: Binding(
  67. get: { selectedVerboseHint },
  68. set: {
  69. selectedVerboseHint = $0.map { AnyView($0) }
  70. hintLabel = "Show Protein and Fat"
  71. }
  72. ),
  73. units: state.units,
  74. type: .boolean,
  75. label: "Show Protein and Fat",
  76. miniHint: "Show protein and fat on the Apple Watch.",
  77. verboseHint: Text("When enabled, protein and fat will show in the carb entry screen of the Apple Watch")
  78. )
  79. SettingInputSection(
  80. decimalValue: $decimalPlaceholder,
  81. booleanValue: $state.confirmBolusFaster,
  82. shouldDisplayHint: $shouldDisplayHint,
  83. selectedVerboseHint: Binding(
  84. get: { selectedVerboseHint },
  85. set: {
  86. selectedVerboseHint = $0.map { AnyView($0) }
  87. hintLabel = "Confirm Bolus Faster"
  88. }
  89. ),
  90. units: state.units,
  91. type: .boolean,
  92. label: "Confirm Bolus Faster",
  93. miniHint: "Removes validation for boluses sent from the paired apple watch.",
  94. verboseHint: Text(
  95. "Enabling this feature removes the confirmation / validation step to initiate a bolus faster from the watch."
  96. )
  97. )
  98. }
  99. .listSectionSpacing(sectionSpacing)
  100. .sheet(isPresented: $shouldDisplayHint) {
  101. SettingInputHintView(
  102. hintDetent: $hintDetent,
  103. shouldDisplayHint: $shouldDisplayHint,
  104. hintLabel: hintLabel ?? "",
  105. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  106. sheetTitle: "Help"
  107. )
  108. }
  109. .navigationTitle("Apple Watch")
  110. .navigationBarTitleDisplayMode(.automatic)
  111. .scrollContentBackground(.hidden)
  112. .background(appState.trioBackgroundColor(for: colorScheme))
  113. }
  114. }