TidepoolStartView.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import SwiftUI
  2. struct TidepoolStartView: View {
  3. @ObservedObject var state: Settings.StateModel
  4. @State private var shouldDisplayHint: Bool = false
  5. @State var hintDetent = PresentationDetent.large
  6. @State private var decimalPlaceholder: Decimal = 0.0
  7. @State private var booleanPlaceholder: Bool = false
  8. @Environment(\.colorScheme) var colorScheme
  9. var color: LinearGradient {
  10. colorScheme == .dark ? LinearGradient(
  11. gradient: Gradient(colors: [
  12. Color.bgDarkBlue,
  13. Color.bgDarkerDarkBlue
  14. ]),
  15. startPoint: .top,
  16. endPoint: .bottom
  17. )
  18. :
  19. LinearGradient(
  20. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  21. startPoint: .top,
  22. endPoint: .bottom
  23. )
  24. }
  25. var body: some View {
  26. Form {
  27. Section(
  28. header: Text("Tidepool Integration"),
  29. content:
  30. {
  31. VStack {
  32. Button {
  33. state.setupTidepool.toggle()
  34. }
  35. label: { Text("Connect to Tidepool").font(.title3) }
  36. .frame(maxWidth: .infinity, alignment: .center)
  37. .buttonStyle(.bordered)
  38. HStack(alignment: .top) {
  39. Text("You can connect Trio to seamlessly upload and manage your diabetes data on Tidepool.")
  40. .font(.footnote)
  41. .foregroundColor(.secondary)
  42. .lineLimit(nil)
  43. Spacer()
  44. Button(
  45. action: {
  46. shouldDisplayHint.toggle()
  47. },
  48. label: {
  49. HStack {
  50. Image(systemName: "questionmark.circle")
  51. }
  52. }
  53. ).buttonStyle(BorderlessButtonStyle())
  54. }.padding(.top)
  55. }.padding(.vertical)
  56. }
  57. ).listRowBackground(Color.chart)
  58. }
  59. .sheet(isPresented: $state.setupTidepool) {
  60. if let serviceUIType = state.serviceUIType,
  61. let pluginHost = state.provider.tidepoolManager.getTidepoolPluginHost()
  62. {
  63. if let serviceUI = state.provider.tidepoolManager.getTidepoolServiceUI() {
  64. TidepoolSettingsView(
  65. serviceUI: serviceUI,
  66. serviceOnBoardDelegate: self.state,
  67. serviceDelegate: self.state
  68. )
  69. } else {
  70. TidepoolSetupView(
  71. serviceUIType: serviceUIType,
  72. pluginHost: pluginHost,
  73. serviceOnBoardDelegate: self.state,
  74. serviceDelegate: self.state
  75. )
  76. }
  77. }
  78. }
  79. .sheet(isPresented: $shouldDisplayHint) {
  80. SettingInputHintView(
  81. hintDetent: $hintDetent,
  82. shouldDisplayHint: $shouldDisplayHint,
  83. hintLabel: "Connect to Tidepool",
  84. 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.",
  85. sheetTitle: "Help"
  86. )
  87. }
  88. .scrollContentBackground(.hidden).background(color)
  89. .navigationTitle("Tidepool")
  90. .navigationBarTitleDisplayMode(.automatic)
  91. }
  92. }