WatchConfigGarminView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. 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("Garmin Configuration"),
  35. content:
  36. {
  37. VStack {
  38. Button {
  39. state.selectGarminDevices()
  40. } label: {
  41. Text("Add Device")
  42. .font(.title3) }
  43. .frame(maxWidth: .infinity, alignment: .center)
  44. .buttonStyle(.bordered)
  45. HStack(alignment: .center) {
  46. Text(
  47. "Add a Garmin Device to Trio."
  48. )
  49. .font(.footnote)
  50. .foregroundColor(.secondary)
  51. .lineLimit(nil)
  52. Spacer()
  53. Button(
  54. action: {
  55. hintLabel = "Add Device"
  56. selectedVerboseHint =
  57. AnyView(
  58. Text(
  59. "Add Garmin Device to Trio. Please look at the docs to see which device are supported."
  60. )
  61. )
  62. shouldDisplayHint.toggle()
  63. },
  64. label: {
  65. HStack {
  66. Image(systemName: "questionmark.circle")
  67. }
  68. }
  69. ).buttonStyle(BorderlessButtonStyle())
  70. }.padding(.top)
  71. }.padding(.vertical)
  72. }
  73. ).listRowBackground(Color.chart)
  74. if !state.devices.isEmpty {
  75. Section(header: Text("Garmin Watch")) {
  76. List {
  77. ForEach(state.devices, id: \.uuid) { device in
  78. Text(device.friendlyName)
  79. }
  80. .onDelete(perform: onDelete)
  81. }
  82. }.listRowBackground(Color.chart)
  83. }
  84. }
  85. .listSectionSpacing(sectionSpacing)
  86. .sheet(isPresented: $shouldDisplayHint) {
  87. SettingInputHintView(
  88. hintDetent: $hintDetent,
  89. shouldDisplayHint: $shouldDisplayHint,
  90. hintLabel: hintLabel ?? "",
  91. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  92. sheetTitle: "Help"
  93. )
  94. }
  95. .navigationTitle("Garmin")
  96. .navigationBarTitleDisplayMode(.automatic)
  97. .scrollContentBackground(.hidden).background(color)
  98. }
  99. }