WatchConfigRootView.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import SwiftUI
  2. import Swinject
  3. extension WatchConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. var body: some View {
  8. Form {
  9. Section(header: Text("Apple Watch")) {
  10. Picker(
  11. selection: $state.selectedAwConfig,
  12. label: Text("Display on Watch")
  13. ) {
  14. ForEach(AwConfig.allCases) { v in
  15. Text(v.displayName).tag(v)
  16. }
  17. }
  18. Toggle("Display Protein & Fat", isOn: $state.displayFatAndProteinOnWatch)
  19. Toggle("Confirm Bolus Faster", isOn: $state.confirmBolusFaster)
  20. }
  21. Section(header: Text("Garmin Watch")) {
  22. List {
  23. ForEach(state.devices, id: \.uuid) { device in
  24. Text(device.friendlyName)
  25. }
  26. .onDelete(perform: onDelete)
  27. }
  28. Button("Add devices") {
  29. state.selectGarminDevices()
  30. }
  31. }
  32. }
  33. .onAppear(perform: configureView)
  34. .navigationTitle("Watch Configuration")
  35. .navigationBarTitleDisplayMode(.automatic)
  36. }
  37. private func onDelete(offsets: IndexSet) {
  38. state.devices.remove(atOffsets: offsets)
  39. state.deleteGarminDevice()
  40. }
  41. }
  42. }