TidepoolStartView.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import SwiftUI
  2. import Swinject
  3. struct TidepoolStartView: BaseView {
  4. let resolver: Resolver
  5. @ObservedObject var state: Settings.StateModel
  6. @State private var shouldDisplayHint: Bool = false
  7. @State var hintDetent = PresentationDetent.large
  8. @State private var decimalPlaceholder: Decimal = 0.0
  9. @State private var booleanPlaceholder: Bool = false
  10. @Environment(\.colorScheme) var colorScheme
  11. @Environment(AppState.self) var appState
  12. var body: some View {
  13. Form {
  14. Section(
  15. header: Text("Tidepool Integration"),
  16. content:
  17. {
  18. VStack {
  19. if let serviceUIType = state.serviceUIType,
  20. let pluginHost = state.provider.tidepoolManager.getTidepoolPluginHost()
  21. {
  22. if let serviceUI = state.provider.tidepoolManager.getTidepoolServiceUI()
  23. {
  24. Button {
  25. state.setupTidepool.toggle()
  26. }
  27. label: {
  28. HStack {
  29. Text("Connected to Tidepool").font(.title3)
  30. ZStack {
  31. Image(systemName: "network")
  32. Image(systemName: "checkmark.circle.fill")
  33. .foregroundColor(.green).font(.caption2)
  34. .offset(x: 9, y: 6)
  35. }
  36. }
  37. }
  38. .frame(maxWidth: .infinity, alignment: .center)
  39. .buttonStyle(.bordered)
  40. } else {
  41. Button {
  42. state.setupTidepool.toggle()
  43. }
  44. label: { Text("Connect to Tidepool").font(.title3) }
  45. .frame(maxWidth: .infinity, alignment: .center)
  46. .buttonStyle(.bordered)
  47. }
  48. }
  49. HStack(alignment: .center) {
  50. Text("You can connect Trio to seamlessly upload and manage your diabetes data on Tidepool.")
  51. .font(.footnote)
  52. .foregroundColor(.secondary)
  53. .lineLimit(nil)
  54. Spacer()
  55. Button(
  56. action: {
  57. shouldDisplayHint.toggle()
  58. },
  59. label: {
  60. HStack {
  61. Image(systemName: "questionmark.circle")
  62. }
  63. }
  64. ).buttonStyle(BorderlessButtonStyle())
  65. }.padding(.top)
  66. }.padding(.vertical)
  67. }
  68. ).listRowBackground(Color.chart)
  69. }
  70. .sheet(isPresented: $state.setupTidepool) {
  71. if let serviceUIType = state.serviceUIType,
  72. let pluginHost = state.provider.tidepoolManager.getTidepoolPluginHost()
  73. {
  74. if let serviceUI = state.provider.tidepoolManager.getTidepoolServiceUI() {
  75. TidepoolSettingsView(
  76. serviceUI: serviceUI,
  77. serviceOnBoardDelegate: self.state,
  78. serviceDelegate: self.state
  79. )
  80. } else {
  81. TidepoolSetupView(
  82. serviceUIType: serviceUIType,
  83. pluginHost: pluginHost,
  84. serviceOnBoardDelegate: self.state,
  85. serviceDelegate: self.state
  86. )
  87. }
  88. }
  89. }
  90. .sheet(isPresented: $shouldDisplayHint) {
  91. SettingInputHintView(
  92. hintDetent: $hintDetent,
  93. shouldDisplayHint: $shouldDisplayHint,
  94. hintLabel: "Connect to Tidepool",
  95. hintText: Text(
  96. "Use your Tidepool credentials to log in. If you don't have a Tidepool account, you can sign up on the login page.\n\nWhen connected, Trio uploads your glucose, carb entries, insulin (bolus and basal), pump settings, and therapy settings to Tidepool.\n\nTherapy settings include basal schedules, carb ratios, insulin sensitivities, and glucose targets."
  97. ),
  98. sheetTitle: String(localized: "Help", comment: "Help sheet title")
  99. )
  100. }
  101. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  102. .navigationTitle("Tidepool")
  103. .navigationBarTitleDisplayMode(.automatic)
  104. .onAppear(perform: configureView)
  105. }
  106. }