CGMRootView.swift 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import SwiftUI
  2. import Swinject
  3. extension CGM {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. var body: some View {
  8. Form {
  9. Section {
  10. Picker("Type", selection: $state.cgm) {
  11. ForEach(CGMType.allCases) { type in
  12. VStack(alignment: .leading) {
  13. Text(type.displayName)
  14. Text(type.subtitle).font(.caption).foregroundColor(.secondary)
  15. }.tag(type)
  16. }
  17. }
  18. if let link = state.cgm.externalLink {
  19. Button("About this source") {
  20. UIApplication.shared.open(link, options: [:], completionHandler: nil)
  21. }
  22. }
  23. }
  24. if [.dexcomG5, .dexcomG6].contains(state.cgm) {
  25. Section(header: Text("Transmitter ID")) {
  26. TextField("XXXXXX", text: $state.transmitterID, onCommit: {
  27. UIApplication.shared.endEditing()
  28. state.onChangeID()
  29. })
  30. .disableAutocorrection(true)
  31. .autocapitalization(.allCharacters)
  32. .keyboardType(.asciiCapable)
  33. }
  34. .onDisappear {
  35. state.onChangeID()
  36. }
  37. }
  38. if state.cgm == .libreTransmitter {
  39. Button("Configure Libre Transmitter") {
  40. state.showModal(for: .libreConfig)
  41. }
  42. Text("Calibrations").navigationLink(to: .calibrations, from: self)
  43. }
  44. if state.cgm == .xdrip {
  45. Section(header: Text("Heartbeat")) {
  46. VStack(alignment: .leading) {
  47. if let cgmTransmitterDeviceAddress = state.cgmTransmitterDeviceAddress {
  48. Text("CGM address :")
  49. Text(cgmTransmitterDeviceAddress)
  50. } else {
  51. Text("CGM is not used as heartbeat.")
  52. }
  53. }
  54. }
  55. }
  56. Section(header: Text("Calendar")) {
  57. Toggle("Create events in calendar", isOn: $state.createCalendarEvents)
  58. if state.calendarIDs.isNotEmpty {
  59. Picker("Calendar", selection: $state.currentCalendarID) {
  60. ForEach(state.calendarIDs, id: \.self) {
  61. Text($0).tag($0)
  62. }
  63. }
  64. }
  65. }
  66. Section(header: Text("Other")) {
  67. Toggle("Upload glucose to Nightscout", isOn: $state.uploadGlucose)
  68. }
  69. }
  70. .onAppear(perform: configureView)
  71. .navigationTitle("CGM")
  72. .navigationBarTitleDisplayMode(.automatic)
  73. }
  74. }
  75. }