WatchConfigAppleWatchView.swift 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import SwiftUI
  2. import Swinject
  3. struct WatchConfigAppleWatchView: BaseView {
  4. let resolver: Resolver
  5. @ObservedObject var state: WatchConfig.StateModel
  6. @State private var shouldDisplayHint: Bool = false
  7. @State var hintDetent = PresentationDetent.large
  8. @State var selectedVerboseHint: AnyView?
  9. @State var hintLabel: String?
  10. @State private var decimalPlaceholder: Decimal = 0.0
  11. @State private var booleanPlaceholder: Bool = false
  12. @Environment(\.colorScheme) var colorScheme
  13. @Environment(AppState.self) var appState
  14. private func onDelete(offsets: IndexSet) {
  15. state.devices.remove(atOffsets: offsets)
  16. state.deleteGarminDevice()
  17. }
  18. var body: some View {
  19. List {
  20. Section(
  21. header: Text("Apple Watch Configuration"),
  22. content: {
  23. VStack {
  24. Picker(
  25. selection: $state.selectedAwConfig,
  26. label: Text("Display on Watch")
  27. ) {
  28. ForEach(AwConfig.allCases) { selection in
  29. Text(selection.displayName).tag(selection)
  30. }
  31. }.padding(.top)
  32. HStack(alignment: .center) {
  33. Text(
  34. "Select the information to display."
  35. )
  36. .font(.footnote)
  37. .foregroundColor(.secondary)
  38. .lineLimit(nil)
  39. Spacer()
  40. Button(
  41. action: {
  42. hintLabel = "Display on Watch"
  43. selectedVerboseHint =
  44. AnyView(VStack(alignment: .leading, spacing: 5) {
  45. Text("Choose between the following:")
  46. Text("• Heart Rate")
  47. Text("• Glucose Target")
  48. Text("• Steps")
  49. Text("• ISF")
  50. Text("• % Override")
  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: "Allow protein and fat entries on 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: "Reduce the number of crown rotations required for bolus confirmation.",
  96. verboseHint: Text(
  97. "Enabling this feature lowers the number of turns on the crown dial required when confirming a bolus."
  98. )
  99. )
  100. Section(
  101. header: Text("Contact Image"),
  102. content: {
  103. VStack {
  104. HStack {
  105. NavigationLink("Contacts Configuration") {
  106. ContactImage.RootView(resolver: resolver)
  107. }.foregroundStyle(Color.accentColor)
  108. }
  109. }
  110. }
  111. ).listRowBackground(Color.chart)
  112. }
  113. .listSectionSpacing(sectionSpacing)
  114. .sheet(isPresented: $shouldDisplayHint) {
  115. SettingInputHintView(
  116. hintDetent: $hintDetent,
  117. shouldDisplayHint: $shouldDisplayHint,
  118. hintLabel: hintLabel ?? "",
  119. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  120. sheetTitle: "Help"
  121. )
  122. }
  123. .navigationTitle("Apple Watch")
  124. .navigationBarTitleDisplayMode(.automatic)
  125. .scrollContentBackground(.hidden)
  126. .background(appState.trioBackgroundColor(for: colorScheme))
  127. }
  128. }