WatchConfigGarminView.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import SwiftUI
  2. struct WatchConfigGarminView: 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("Garmin Configuration"),
  20. content:
  21. {
  22. VStack {
  23. Button {
  24. state.selectGarminDevices()
  25. } label: {
  26. Text("Add Device")
  27. .font(.title3) }
  28. .frame(maxWidth: .infinity, alignment: .center)
  29. .buttonStyle(.bordered)
  30. HStack(alignment: .center) {
  31. Text(
  32. "Add a Garmin Device to Trio."
  33. )
  34. .font(.footnote)
  35. .foregroundColor(.secondary)
  36. .lineLimit(nil)
  37. Spacer()
  38. Button(
  39. action: {
  40. hintLabel = "Add Device"
  41. selectedVerboseHint =
  42. AnyView(
  43. Text(
  44. "Add Garmin Device to Trio. Please look at the docs to see which devices are supported."
  45. )
  46. )
  47. shouldDisplayHint.toggle()
  48. },
  49. label: {
  50. HStack {
  51. Image(systemName: "questionmark.circle")
  52. }
  53. }
  54. ).buttonStyle(BorderlessButtonStyle())
  55. }.padding(.top)
  56. }.padding(.vertical)
  57. }
  58. ).listRowBackground(Color.chart)
  59. if !state.devices.isEmpty {
  60. Section(header: Text("Garmin Watch")) {
  61. List {
  62. ForEach(state.devices, id: \.uuid) { device in
  63. Text(device.friendlyName)
  64. }
  65. .onDelete(perform: onDelete)
  66. }
  67. }.listRowBackground(Color.chart)
  68. }
  69. }
  70. .listSectionSpacing(sectionSpacing)
  71. .sheet(isPresented: $shouldDisplayHint) {
  72. SettingInputHintView(
  73. hintDetent: $hintDetent,
  74. shouldDisplayHint: $shouldDisplayHint,
  75. hintLabel: hintLabel ?? "",
  76. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  77. sheetTitle: "Help"
  78. )
  79. }
  80. .navigationTitle("Garmin")
  81. .navigationBarTitleDisplayMode(.automatic)
  82. .scrollContentBackground(.hidden)
  83. .background(appState.trioBackgroundColor(for: colorScheme))
  84. }
  85. }