NightscoutFetchView.swift 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. @Environment(AppState.self) var appState
  12. var body: some View {
  13. List {
  14. SettingInputSection(
  15. decimalValue: $decimalPlaceholder,
  16. booleanValue: $state.isDownloadEnabled,
  17. shouldDisplayHint: $shouldDisplayHint,
  18. selectedVerboseHint: Binding(
  19. get: { selectedVerboseHint },
  20. set: {
  21. selectedVerboseHint = $0.map { AnyView($0) }
  22. hintLabel = "Allow Fetching from Nightscout"
  23. }
  24. ),
  25. units: state.units,
  26. type: .boolean,
  27. label: "Allow Fetching from Nightscout",
  28. miniHint: "Enable fetching of selected data sets from Nightscout.",
  29. verboseHint: VStack(alignment: .leading, spacing: 10) {
  30. Text("Default: OFF").bold()
  31. Text(
  32. "The Fetch Treatments toggle enables fetching of carbs and temp targets entered in Careportal or by another uploading device than Trio from Nightscout."
  33. )
  34. },
  35. headerText: "Remote & Fetch Capabilities"
  36. )
  37. if state.isDownloadEnabled {
  38. SettingInputSection(
  39. decimalValue: $decimalPlaceholder,
  40. booleanValue: $state.allowAnnouncements,
  41. shouldDisplayHint: $shouldDisplayHint,
  42. selectedVerboseHint: Binding(
  43. get: { selectedVerboseHint },
  44. set: {
  45. selectedVerboseHint = $0.map { AnyView($0) }
  46. hintLabel = "Allow Remote Control of Trio"
  47. }
  48. ),
  49. units: state.units,
  50. type: .boolean,
  51. label: "Allow Remote Control of Trio",
  52. miniHint: "Enables selected remote control capabilities via Nightscout.",
  53. verboseHint: VStack(alignment: .leading, spacing: 10) {
  54. Text("Default: OFF").bold()
  55. Text("When enabled you allow the following remote functions through announcements from Nightscout:")
  56. VStack(alignment: .leading) {
  57. Text("• Suspend/Resume Pump")
  58. Text("• Opening/Closing Loop")
  59. Text("• Set Temp Basal")
  60. Text("• Enact Bolus")
  61. }
  62. }
  63. )
  64. } else {
  65. Section {
  66. Text("'Allow Fetching from Nightscout' must be enabled to allow for Trio Remote Control.")
  67. }.listRowBackground(Color.tabBar)
  68. }
  69. }
  70. .listSectionSpacing(sectionSpacing)
  71. .sheet(isPresented: $shouldDisplayHint) {
  72. SettingInputHintView(
  73. hintDetent: $hintDetent,
  74. shouldDisplayHint: $shouldDisplayHint,
  75. hintLabel: hintLabel ?? "",
  76. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  77. sheetTitle: "Help"
  78. )
  79. }
  80. .navigationTitle("Fetch & Remote")
  81. .navigationBarTitleDisplayMode(.automatic)
  82. .scrollContentBackground(.hidden)
  83. .background(appState.trioBackgroundColor(for: colorScheme))
  84. }
  85. }