WatchConfigRootView.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. }
  36. Toggle("Display Protein & Fat", isOn: $state.displayFatAndProteinOnWatch)
  37. Toggle("Confirm Bolus Faster", isOn: $state.confirmBolusFaster)
  38. Section(header: Text("Garmin Watch")) {
  39. List {
  40. ForEach(state.devices, id: \.uuid) { device in
  41. Text(device.friendlyName)
  42. }
  43. .onDelete(perform: onDelete)
  44. }
  45. Button("Add devices") {
  46. state.selectGarminDevices()
  47. }
  48. }
  49. }
  50. .scrollContentBackground(.hidden).background(color)
  51. .onAppear(perform: configureView)
  52. .navigationTitle("Watch Configuration")
  53. .navigationBarTitleDisplayMode(.automatic)
  54. }
  55. private func onDelete(offsets: IndexSet) {
  56. state.devices.remove(atOffsets: offsets)
  57. state.deleteGarminDevice()
  58. }
  59. }
  60. }