TidepoolStartView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. Button {
  35. state.setupTidepool.toggle()
  36. }
  37. label: { Text("Connect to Tidepool").font(.title3) }
  38. .frame(maxWidth: .infinity, alignment: .center)
  39. .buttonStyle(.bordered)
  40. HStack(alignment: .top) {
  41. Text("You can connect Trio to seamlessly upload and manage your diabetes data on Tidepool.")
  42. .font(.footnote)
  43. .foregroundColor(.secondary)
  44. .lineLimit(nil)
  45. Spacer()
  46. Button(
  47. action: {
  48. shouldDisplayHint.toggle()
  49. },
  50. label: {
  51. HStack {
  52. Image(systemName: "questionmark.circle")
  53. }
  54. }
  55. ).buttonStyle(BorderlessButtonStyle())
  56. }.padding(.top)
  57. }.padding(.vertical)
  58. }
  59. ).listRowBackground(Color.chart)
  60. }
  61. .sheet(isPresented: $state.setupTidepool) {
  62. if let serviceUIType = state.serviceUIType,
  63. let pluginHost = state.provider.tidepoolManager.getTidepoolPluginHost()
  64. {
  65. if let serviceUI = state.provider.tidepoolManager.getTidepoolServiceUI() {
  66. TidepoolSettingsView(
  67. serviceUI: serviceUI,
  68. serviceOnBoardDelegate: self.state,
  69. serviceDelegate: self.state
  70. )
  71. } else {
  72. TidepoolSetupView(
  73. serviceUIType: serviceUIType,
  74. pluginHost: pluginHost,
  75. serviceOnBoardDelegate: self.state,
  76. serviceDelegate: self.state
  77. )
  78. }
  79. }
  80. }
  81. .sheet(isPresented: $shouldDisplayHint) {
  82. SettingInputHintView(
  83. hintDetent: $hintDetent,
  84. shouldDisplayHint: $shouldDisplayHint,
  85. hintLabel: "Connect to Tidepool",
  86. 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.",
  87. sheetTitle: "Help"
  88. )
  89. }
  90. .scrollContentBackground(.hidden).background(color)
  91. .navigationTitle("Tidepool")
  92. .navigationBarTitleDisplayMode(.automatic)
  93. .onAppear(perform: configureView)
  94. }
  95. }