WatchConfigAppleWatchView.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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: .center) {
  46. Text(
  47. "Show the choosen dataitem on your Apple Watch."
  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(Text("Choose which dataitem you want to display on your Apple Watch."))
  58. shouldDisplayHint.toggle()
  59. },
  60. label: {
  61. HStack {
  62. Image(systemName: "questionmark.circle")
  63. }
  64. }
  65. ).buttonStyle(BorderlessButtonStyle())
  66. }.padding(.top)
  67. }.padding(.bottom)
  68. }
  69. ).listRowBackground(Color.chart)
  70. SettingInputSection(
  71. decimalValue: $decimalPlaceholder,
  72. booleanValue: $state.displayFatAndProteinOnWatch,
  73. shouldDisplayHint: $shouldDisplayHint,
  74. selectedVerboseHint: Binding(
  75. get: { selectedVerboseHint },
  76. set: {
  77. selectedVerboseHint = $0.map { AnyView($0) }
  78. hintLabel = "Show Protein and Fat"
  79. }
  80. ),
  81. units: state.units,
  82. type: .boolean,
  83. label: "Show Protein and Fat",
  84. miniHint: "Show protein and fat on the Apple Watch.",
  85. verboseHint: Text("When enabled, protein and fat will show in the carb entry screen of the Apple Watch")
  86. )
  87. SettingInputSection(
  88. decimalValue: $decimalPlaceholder,
  89. booleanValue: $state.confirmBolusFaster,
  90. shouldDisplayHint: $shouldDisplayHint,
  91. selectedVerboseHint: Binding(
  92. get: { selectedVerboseHint },
  93. set: {
  94. selectedVerboseHint = $0.map { AnyView($0) }
  95. hintLabel = "Confirm Bolus Faster"
  96. }
  97. ),
  98. units: state.units,
  99. type: .boolean,
  100. label: "Confirm Bolus Faster",
  101. miniHint: "Removes validation for boluses sent from the paired apple watch.",
  102. verboseHint: Text(
  103. "Enabling this feature removes the confirmation / validation step to initiate a bolus faster from the watch."
  104. )
  105. )
  106. }
  107. .sheet(isPresented: $shouldDisplayHint) {
  108. SettingInputHintView(
  109. hintDetent: $hintDetent,
  110. shouldDisplayHint: $shouldDisplayHint,
  111. hintLabel: hintLabel ?? "",
  112. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  113. sheetTitle: "Help"
  114. )
  115. }
  116. .navigationTitle("Apple Watch")
  117. .navigationBarTitleDisplayMode(.automatic)
  118. .scrollContentBackground(.hidden).background(color)
  119. }
  120. }