WatchConfigAppleWatchView.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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: 10) {
  43. Text("Choose between the following options:")
  44. VStack(alignment: .leading, spacing: 5) {
  45. Text("• Heart Rate")
  46. Text("• Glucose Target")
  47. Text("• Steps")
  48. Text("• ISF")
  49. Text("• % Override")
  50. }
  51. })
  52. shouldDisplayHint.toggle()
  53. },
  54. label: {
  55. HStack {
  56. Image(systemName: "questionmark.circle")
  57. }
  58. }
  59. ).buttonStyle(BorderlessButtonStyle())
  60. }.padding(.top)
  61. }.padding(.bottom)
  62. }
  63. ).listRowBackground(Color.chart)
  64. SettingInputSection(
  65. decimalValue: $decimalPlaceholder,
  66. booleanValue: $state.displayFatAndProteinOnWatch,
  67. shouldDisplayHint: $shouldDisplayHint,
  68. selectedVerboseHint: Binding(
  69. get: { selectedVerboseHint },
  70. set: {
  71. selectedVerboseHint = $0.map { AnyView($0) }
  72. hintLabel = "Show Protein and Fat"
  73. }
  74. ),
  75. units: state.units,
  76. type: .boolean,
  77. label: "Show Protein and Fat",
  78. miniHint: "Show protein and fat on the Apple Watch.",
  79. verboseHint: Text("When enabled, protein and fat will show in the carb entry screen of the Apple Watch")
  80. )
  81. SettingInputSection(
  82. decimalValue: $decimalPlaceholder,
  83. booleanValue: $state.confirmBolusFaster,
  84. shouldDisplayHint: $shouldDisplayHint,
  85. selectedVerboseHint: Binding(
  86. get: { selectedVerboseHint },
  87. set: {
  88. selectedVerboseHint = $0.map { AnyView($0) }
  89. hintLabel = "Confirm Bolus Faster"
  90. }
  91. ),
  92. units: state.units,
  93. type: .boolean,
  94. label: "Confirm Bolus Faster",
  95. miniHint: "Removes validation for boluses sent from the paired apple watch.",
  96. verboseHint: Text(
  97. "Enabling this feature removes the confirmation / validation step to initiate a bolus faster from the watch."
  98. )
  99. )
  100. }
  101. .listSectionSpacing(sectionSpacing)
  102. .sheet(isPresented: $shouldDisplayHint) {
  103. SettingInputHintView(
  104. hintDetent: $hintDetent,
  105. shouldDisplayHint: $shouldDisplayHint,
  106. hintLabel: hintLabel ?? "",
  107. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  108. sheetTitle: "Help"
  109. )
  110. }
  111. .navigationTitle("Apple Watch")
  112. .navigationBarTitleDisplayMode(.automatic)
  113. .scrollContentBackground(.hidden)
  114. .background(appState.trioBackgroundColor(for: colorScheme))
  115. }
  116. }