TidepoolStartView.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. var color: LinearGradient {
  12. colorScheme == .dark ? LinearGradient(
  13. gradient: Gradient(colors: [
  14. Color.bgDarkBlue,
  15. Color.bgDarkerDarkBlue
  16. ]),
  17. startPoint: .top,
  18. endPoint: .bottom
  19. )
  20. :
  21. LinearGradient(
  22. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  23. startPoint: .top,
  24. endPoint: .bottom
  25. )
  26. }
  27. var body: some View {
  28. Form {
  29. Section(
  30. header: Text("Tidepool Integration"),
  31. content:
  32. {
  33. VStack {
  34. if let serviceUIType = state.serviceUIType,
  35. let pluginHost = state.provider.tidepoolManager.getTidepoolPluginHost()
  36. {
  37. if let serviceUI = state.provider.tidepoolManager.getTidepoolServiceUI()
  38. {
  39. Button {
  40. state.setupTidepool.toggle()
  41. }
  42. label: {
  43. HStack {
  44. Text("Connected to Tidepool").font(.title3)
  45. ZStack {
  46. Image(systemName: "network")
  47. Image(systemName: "checkmark.circle.fill")
  48. .foregroundColor(.green).font(.caption2)
  49. .offset(x: 9, y: 6)
  50. }
  51. }
  52. }
  53. .frame(maxWidth: .infinity, alignment: .center)
  54. .buttonStyle(.bordered)
  55. } else {
  56. Button {
  57. state.setupTidepool.toggle()
  58. }
  59. label: { Text("Connect to Tidepool").font(.title3) }
  60. .frame(maxWidth: .infinity, alignment: .center)
  61. .buttonStyle(.bordered)
  62. }
  63. }
  64. HStack(alignment: .top) {
  65. Text("You can connect Trio to seamlessly upload and manage your diabetes data on Tidepool.")
  66. .font(.footnote)
  67. .foregroundColor(.secondary)
  68. .lineLimit(nil)
  69. Spacer()
  70. Button(
  71. action: {
  72. shouldDisplayHint.toggle()
  73. },
  74. label: {
  75. HStack {
  76. Image(systemName: "questionmark.circle")
  77. }
  78. }
  79. ).buttonStyle(BorderlessButtonStyle())
  80. }.padding(.top)
  81. }.padding(.vertical)
  82. }
  83. ).listRowBackground(Color.chart)
  84. }
  85. .sheet(isPresented: $state.setupTidepool) {
  86. if let serviceUIType = state.serviceUIType,
  87. let pluginHost = state.provider.tidepoolManager.getTidepoolPluginHost()
  88. {
  89. if let serviceUI = state.provider.tidepoolManager.getTidepoolServiceUI() {
  90. TidepoolSettingsView(
  91. serviceUI: serviceUI,
  92. serviceOnBoardDelegate: self.state,
  93. serviceDelegate: self.state
  94. )
  95. } else {
  96. TidepoolSetupView(
  97. serviceUIType: serviceUIType,
  98. pluginHost: pluginHost,
  99. serviceOnBoardDelegate: self.state,
  100. serviceDelegate: self.state
  101. )
  102. }
  103. }
  104. }
  105. .sheet(isPresented: $shouldDisplayHint) {
  106. SettingInputHintView(
  107. hintDetent: $hintDetent,
  108. shouldDisplayHint: $shouldDisplayHint,
  109. hintLabel: "Connect to Tidepool",
  110. hintText: "When connected, uploading of carbs, bolus, basal and glucose from Trio to your Tidepool account is enabled.\n\nUse your Tidepool credentials to login. If you dont already have a Tidepool account, you can sign up for one on the login page.",
  111. sheetTitle: "Help"
  112. )
  113. }
  114. .scrollContentBackground(.hidden).background(color)
  115. .navigationTitle("Tidepool")
  116. .navigationBarTitleDisplayMode(.automatic)
  117. .onAppear(perform: configureView)
  118. }
  119. }