WatchConfigAppleWatchView.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. Form {
  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: .top) {
  46. Text(
  47. "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  48. )
  49. .font(.footnote)
  50. .foregroundColor(.secondary)
  51. .lineLimit(nil)
  52. Spacer()
  53. Button(
  54. action: {
  55. hintLabel = "Display on Watch"
  56. selectedVerboseHint = AnyView(Text("Display on Watch… bla bla bla"))
  57. shouldDisplayHint.toggle()
  58. },
  59. label: {
  60. HStack {
  61. Image(systemName: "questionmark.circle")
  62. }
  63. }
  64. ).buttonStyle(BorderlessButtonStyle())
  65. }.padding(.top)
  66. }.padding(.bottom)
  67. }
  68. ).listRowBackground(Color.chart)
  69. SettingInputSection(
  70. decimalValue: $decimalPlaceholder,
  71. booleanValue: $state.displayFatAndProteinOnWatch,
  72. shouldDisplayHint: $shouldDisplayHint,
  73. selectedVerboseHint: Binding(
  74. get: { selectedVerboseHint },
  75. set: {
  76. selectedVerboseHint = $0.map { AnyView($0) }
  77. hintLabel = "Show Protein and Fat"
  78. }
  79. ),
  80. units: state.units,
  81. type: .boolean,
  82. label: "Show Protein and Fat",
  83. miniHint: "Show protein and fat on the Apple Watch",
  84. verboseHint: Text("When enabled, protein and fat will show in the carb entry screen of the Apple Watch")
  85. )
  86. SettingInputSection(
  87. decimalValue: $decimalPlaceholder,
  88. booleanValue: $state.confirmBolusFaster,
  89. shouldDisplayHint: $shouldDisplayHint,
  90. selectedVerboseHint: Binding(
  91. get: { selectedVerboseHint },
  92. set: {
  93. selectedVerboseHint = $0.map { AnyView($0) }
  94. hintLabel = "Confirm Bolus Faster"
  95. }
  96. ),
  97. units: state.units,
  98. type: .boolean,
  99. label: "Confirm Bolus Faster",
  100. miniHint: "Removes validation for boluses sent from the paired apple watch",
  101. verboseHint: Text("Enabling this feature removes the confirmation / validation step to initiate a bolus faster from the watch.")
  102. )
  103. }
  104. .sheet(isPresented: $shouldDisplayHint) {
  105. SettingInputHintView(
  106. hintDetent: $hintDetent,
  107. shouldDisplayHint: $shouldDisplayHint,
  108. hintLabel: hintLabel ?? "",
  109. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  110. sheetTitle: "Help"
  111. )
  112. }
  113. .navigationTitle("Apple Watch")
  114. .navigationBarTitleDisplayMode(.automatic)
  115. .scrollContentBackground(.hidden).background(color)
  116. }
  117. }