NightscoutFetchView.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import SwiftUI
  2. struct NightscoutFetchView: View {
  3. @ObservedObject var state: NightscoutConfig.StateModel
  4. @State private var shouldDisplayHint: Bool = false
  5. @State var hintDetent = PresentationDetent.large
  6. @State var selectedVerboseHint: AnyView?
  7. @State var hintLabel: String?
  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. SettingInputSection(
  30. decimalValue: $decimalPlaceholder,
  31. booleanValue: $state.isDownloadEnabled,
  32. shouldDisplayHint: $shouldDisplayHint,
  33. selectedVerboseHint: Binding(
  34. get: { selectedVerboseHint },
  35. set: {
  36. selectedVerboseHint = $0.map { AnyView($0) }
  37. hintLabel = "Allow Fetching from Nightscout"
  38. }
  39. ),
  40. units: state.units,
  41. type: .boolean,
  42. label: "Allow Fetching from Nightscout",
  43. miniHint: """
  44. Enable fetching of selected data sets from Nightscout
  45. See hint for more details.
  46. """,
  47. verboseHint: Text(
  48. "The Fetch Treatments toggle enables fetching of carbs and temp targets entered in Careportal or by another uploading device than Trio from Nightscout."
  49. ),
  50. headerText: "Remote & Fetch Capabilities"
  51. )
  52. if state.isDownloadEnabled {
  53. SettingInputSection(
  54. decimalValue: $decimalPlaceholder,
  55. booleanValue: $state.allowAnnouncements,
  56. shouldDisplayHint: $shouldDisplayHint,
  57. selectedVerboseHint: Binding(
  58. get: { selectedVerboseHint },
  59. set: {
  60. selectedVerboseHint = $0.map { AnyView($0) }
  61. hintLabel = "Allow Remote Control of Trio"
  62. }
  63. ),
  64. units: state.units,
  65. type: .boolean,
  66. label: "Allow Remote Control of Trio",
  67. miniHint: """
  68. Enables selected remote control capabilities via Nightscout
  69. See hint for more details
  70. """,
  71. verboseHint: VStack(spacing: 10) {
  72. Text("When enabled you allow these remote functions through announcements from Nightscout:")
  73. VStack(alignment: .leading) {
  74. Text("• Suspend/Resume Pump")
  75. Text("• Opening/Closing Loop")
  76. Text("• Set Temp Basal")
  77. Text("• Enact Bolus")
  78. }
  79. }
  80. )
  81. } else {
  82. Section {
  83. Text("'Allow Fetching from Nightscout' must be enabled to allow for Trio Remote Control.")
  84. }.listRowBackground(Color.tabBar)
  85. }
  86. }
  87. .sheet(isPresented: $shouldDisplayHint) {
  88. SettingInputHintView(
  89. hintDetent: $hintDetent,
  90. shouldDisplayHint: $shouldDisplayHint,
  91. hintLabel: hintLabel ?? "",
  92. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  93. sheetTitle: "Help"
  94. )
  95. }
  96. .navigationTitle("Fetch & Remote")
  97. .navigationBarTitleDisplayMode(.automatic)
  98. .scrollContentBackground(.hidden).background(color)
  99. }
  100. }