NightscoutFetchView.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: "Enable fetching of selected data sets from Nightscout",
  44. verboseHint: VStack(spacing: 10) {
  45. Text("Default: OFF").bold()
  46. Text(
  47. "The Fetch Treatments toggle enables fetching of carbs and temp targets entered in Careportal or by another uploading device than Trio from Nightscout."
  48. )
  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: "Enables selected remote control capabilities via Nightscout",
  68. verboseHint: VStack(spacing: 10) {
  69. Text("Default: OFF").bold()
  70. Text("When enabled you allow the following remote functions through announcements from Nightscout:")
  71. VStack(alignment: .leading) {
  72. Text("• Suspend/Resume Pump")
  73. Text("• Opening/Closing Loop")
  74. Text("• Set Temp Basal")
  75. Text("• Enact Bolus")
  76. }
  77. }
  78. )
  79. } else {
  80. Section {
  81. Text("'Allow Fetching from Nightscout' must be enabled to allow for Trio Remote Control.")
  82. }.listRowBackground(Color.tabBar)
  83. }
  84. }
  85. .sheet(isPresented: $shouldDisplayHint) {
  86. SettingInputHintView(
  87. hintDetent: $hintDetent,
  88. shouldDisplayHint: $shouldDisplayHint,
  89. hintLabel: hintLabel ?? "",
  90. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  91. sheetTitle: "Help"
  92. )
  93. }
  94. .navigationTitle("Fetch & Remote")
  95. .navigationBarTitleDisplayMode(.automatic)
  96. .scrollContentBackground(.hidden).background(color)
  97. }
  98. }