CGMRootView.swift 3.3 KB

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