WatchConfigAppleWatchView.swift 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. var color: LinearGradient {
  12. colorScheme == .dark ? LinearGradient(
  13. gradient: Gradient(colors: [
  14. Color.bgDarkBlue,
  15. Color.bgDarkerDarkBlue
  16. ]),
  17. startPoint: .top,
  18. endPoint: .bottom
  19. )
  20. :
  21. LinearGradient(
  22. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  23. startPoint: .top,
  24. endPoint: .bottom
  25. )
  26. }
  27. private func onDelete(offsets: IndexSet) {
  28. state.devices.remove(atOffsets: offsets)
  29. state.deleteGarminDevice()
  30. }
  31. var body: some View {
  32. List {
  33. Section(
  34. header: Text("Apple Watch Configuration"),
  35. content: {
  36. VStack {
  37. Picker(
  38. selection: $state.selectedAwConfig,
  39. label: Text("Display on Watch")
  40. ) {
  41. ForEach(AwConfig.allCases) { selection in
  42. Text(selection.displayName).tag(selection)
  43. }
  44. }.padding(.top)
  45. HStack(alignment: .center) {
  46. Text(
  47. "Select the information to display."
  48. )
  49. .font(.footnote)
  50. .foregroundColor(.secondary)
  51. .lineLimit(nil)
  52. Spacer()
  53. Button(
  54. action: {
  55. hintLabel = "Display on Watch"
  56. selectedVerboseHint =
  57. AnyView(VStack(alignment: .leading, spacing: 10) {
  58. Text("Choose between the following options:")
  59. VStack(alignment: .leading, spacing: 5) {
  60. Text("• Heart Rate")
  61. Text("• Glucose Target")
  62. Text("• Steps")
  63. Text("• ISF")
  64. Text("• % Override")
  65. }
  66. })
  67. shouldDisplayHint.toggle()
  68. },
  69. label: {
  70. HStack {
  71. Image(systemName: "questionmark.circle")
  72. }
  73. }
  74. ).buttonStyle(BorderlessButtonStyle())
  75. }.padding(.top)
  76. }.padding(.bottom)
  77. }
  78. ).listRowBackground(Color.chart)
  79. SettingInputSection(
  80. decimalValue: $decimalPlaceholder,
  81. booleanValue: $state.displayFatAndProteinOnWatch,
  82. shouldDisplayHint: $shouldDisplayHint,
  83. selectedVerboseHint: Binding(
  84. get: { selectedVerboseHint },
  85. set: {
  86. selectedVerboseHint = $0.map { AnyView($0) }
  87. hintLabel = "Show Protein and Fat"
  88. }
  89. ),
  90. units: state.units,
  91. type: .boolean,
  92. label: "Show Protein and Fat",
  93. miniHint: "Show protein and fat on the Apple Watch.",
  94. verboseHint: Text("When enabled, protein and fat will show in the carb entry screen of the Apple Watch")
  95. )
  96. SettingInputSection(
  97. decimalValue: $decimalPlaceholder,
  98. booleanValue: $state.confirmBolusFaster,
  99. shouldDisplayHint: $shouldDisplayHint,
  100. selectedVerboseHint: Binding(
  101. get: { selectedVerboseHint },
  102. set: {
  103. selectedVerboseHint = $0.map { AnyView($0) }
  104. hintLabel = "Confirm Bolus Faster"
  105. }
  106. ),
  107. units: state.units,
  108. type: .boolean,
  109. label: "Confirm Bolus Faster",
  110. miniHint: "Removes validation for boluses sent from the paired apple watch.",
  111. verboseHint: Text(
  112. "Enabling this feature removes the confirmation / validation step to initiate a bolus faster from the watch."
  113. )
  114. )
  115. }
  116. .listSectionSpacing(sectionSpacing)
  117. .sheet(isPresented: $shouldDisplayHint) {
  118. SettingInputHintView(
  119. hintDetent: $hintDetent,
  120. shouldDisplayHint: $shouldDisplayHint,
  121. hintLabel: hintLabel ?? "",
  122. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  123. sheetTitle: "Help"
  124. )
  125. }
  126. .navigationTitle("Apple Watch")
  127. .navigationBarTitleDisplayMode(.automatic)
  128. .scrollContentBackground(.hidden).background(color)
  129. }
  130. }