WatchConfigRootView.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import SwiftUI
  2. import Swinject
  3. extension WatchConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @Environment(\.colorScheme) var colorScheme
  8. var color: LinearGradient {
  9. colorScheme == .dark ? LinearGradient(
  10. gradient: Gradient(colors: [
  11. Color.bgDarkBlue,
  12. Color.bgDarkerDarkBlue
  13. ]),
  14. startPoint: .top,
  15. endPoint: .bottom
  16. )
  17. :
  18. LinearGradient(
  19. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  20. startPoint: .top,
  21. endPoint: .bottom
  22. )
  23. }
  24. var body: some View {
  25. Form {
  26. Section(header: Text("Apple Watch")) {
  27. Picker(
  28. selection: $state.selectedAwConfig,
  29. label: Text("Display on Watch")
  30. ) {
  31. ForEach(AwConfig.allCases) { v in
  32. Text(v.displayName).tag(v)
  33. }
  34. }
  35. Toggle("Display Protein & Fat", isOn: $state.displayFatAndProteinOnWatch)
  36. Toggle("Confirm Bolus Faster", isOn: $state.confirmBolusFaster)
  37. }
  38. <<<<<<< HEAD
  39. Toggle("Display Protein & Fat", isOn: $state.displayFatAndProteinOnWatch)
  40. Toggle("Confirm Bolus Faster", isOn: $state.confirmBolusFaster)
  41. =======
  42. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  43. Section(header: Text("Garmin Watch")) {
  44. List {
  45. ForEach(state.devices, id: \.uuid) { device in
  46. Text(device.friendlyName)
  47. }
  48. .onDelete(perform: onDelete)
  49. }
  50. Button("Add devices") {
  51. state.selectGarminDevices()
  52. }
  53. }
  54. }
  55. .scrollContentBackground(.hidden).background(color)
  56. .onAppear(perform: configureView)
  57. .navigationTitle("Watch Configuration")
  58. .navigationBarTitleDisplayMode(.automatic)
  59. }
  60. private func onDelete(offsets: IndexSet) {
  61. state.devices.remove(atOffsets: offsets)
  62. state.deleteGarminDevice()
  63. }
  64. }
  65. }