OtherCGMView.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import LoopKitUI
  2. import SwiftUI
  3. import Swinject
  4. struct OtherCGMView: BaseView {
  5. let resolver: Resolver
  6. @ObservedObject var state: CGM.StateModel
  7. @Environment(\.colorScheme) var colorScheme
  8. @Environment(AppState.self) var appState
  9. @Environment(\.presentationMode) var presentationMode
  10. var body: some View {
  11. NavigationView {
  12. Form {
  13. Section(
  14. header: Text("Configuration"),
  15. content: {
  16. if state.cgmCurrent.type == .nightscout {
  17. NavigationLink(
  18. destination: NightscoutConfig.RootView(resolver: resolver, displayClose: false),
  19. label: { Text("Config Nightscout") }
  20. )
  21. } else if state.cgmCurrent.type == .xdrip {
  22. VStack(alignment: .leading) {
  23. if let cgmTransmitterDeviceAddress = state.cgmTransmitterDeviceAddress {
  24. Text("CGM address :").padding(.top)
  25. Text(cgmTransmitterDeviceAddress)
  26. } else {
  27. Text("CGM is not used as heartbeat.").padding(.top)
  28. }
  29. HStack(alignment: .center) {
  30. Text(
  31. "A heartbeat tells Trio to start a loop cycle. This is required for closed loop."
  32. )
  33. .font(.footnote)
  34. .foregroundColor(.secondary)
  35. .lineLimit(nil)
  36. Spacer()
  37. }.padding(.vertical)
  38. }
  39. }
  40. if let link = state.cgmCurrent.type.externalLink {
  41. Button {
  42. UIApplication.shared.open(link, options: [:], completionHandler: nil)
  43. } label: {
  44. HStack {
  45. Text("About this source")
  46. Spacer()
  47. Image(systemName: "chevron.right")
  48. }
  49. }
  50. .frame(maxWidth: .infinity, alignment: .leading)
  51. }
  52. if let appURL = state.urlOfApp() {
  53. Button {
  54. UIApplication.shared.open(appURL, options: [:]) { success in
  55. if !success {
  56. self.router.alertMessage
  57. .send(MessageContent(content: "Unable to open the app", type: .warning))
  58. }
  59. }
  60. }
  61. label: {
  62. HStack {
  63. Text(state.displayNameOfApp() ?? "-")
  64. Spacer()
  65. Image(systemName: "chevron.right")
  66. }
  67. }
  68. .frame(maxWidth: .infinity, alignment: .leading)
  69. }
  70. }
  71. ).listRowBackground(Color.chart)
  72. Button {
  73. state.deleteCGM()
  74. presentationMode.wrappedValue.dismiss()
  75. } label: {
  76. Text("Delete CGM")
  77. .font(.headline)
  78. .foregroundStyle(Color.white)
  79. .frame(maxWidth: .infinity, alignment: .center)
  80. .frame(height: 35)
  81. }
  82. .listRowBackground(Color(.systemRed))
  83. .clipShape(RoundedRectangle(cornerRadius: 8))
  84. }
  85. .navigationTitle(state.cgmCurrent.displayName)
  86. .navigationBarTitleDisplayMode(.inline)
  87. .toolbar {
  88. /// proper positioning should be .leading
  89. /// but to keep this in line with LoopKit submodules, set placement to .trailing
  90. ToolbarItem(placement: .topBarLeading) {
  91. Button("Close") {
  92. presentationMode.wrappedValue.dismiss()
  93. }
  94. }
  95. }
  96. .scrollContentBackground(.hidden)
  97. .background(appState.trioBackgroundColor(for: colorScheme))
  98. }
  99. }
  100. }