NightscoutFetchView.swift 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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: String?
  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
  37. hintLabel = "Allow Fetching from Nightscout"
  38. }
  39. ),
  40. type: .boolean,
  41. label: "Allow Fetching from Nightscout",
  42. miniHint: "Enable fetching of selected data sets from Nightscout. See hint for more details.",
  43. verboseHint: "The Fetch Treatments toggle enables fetching of carbs and temp targets entered in Careportal or by another uploading device than Trio from Nightscout.",
  44. headerText: "Remote & Fetch Capabilities"
  45. )
  46. if state.isDownloadEnabled {
  47. SettingInputSection(
  48. decimalValue: $decimalPlaceholder,
  49. booleanValue: $state.allowAnnouncements,
  50. shouldDisplayHint: $shouldDisplayHint,
  51. selectedVerboseHint: Binding(
  52. get: { selectedVerboseHint },
  53. set: {
  54. selectedVerboseHint = $0
  55. hintLabel = "Allow Remote Control of Trio"
  56. }
  57. ),
  58. type: .boolean,
  59. label: "Allow Remote Control of Trio",
  60. miniHint: "Enables selected remote control capabilities via Nightscout. See hint for more details.",
  61. verboseHint: "When enabled you allow these remote functions through announcements from Nightscout: \n • Suspend/Resume Pump \n • Opening/Closing Loop \n • Set Temp Basal \n • Enact Bolus"
  62. )
  63. } else {
  64. Section {
  65. Text("'Allow Fetching from Nightscout' must be enabled to allow for Trio Remote Control.")
  66. }.listRowBackground(Color.tabBar)
  67. }
  68. }
  69. .sheet(isPresented: $shouldDisplayHint) {
  70. SettingInputHintView(
  71. hintDetent: $hintDetent,
  72. shouldDisplayHint: $shouldDisplayHint,
  73. hintLabel: hintLabel ?? "",
  74. hintText: selectedVerboseHint ?? "",
  75. sheetTitle: "Help"
  76. )
  77. }
  78. .navigationTitle("Fetch and Remote")
  79. .navigationBarTitleDisplayMode(.automatic)
  80. .scrollContentBackground(.hidden).background(color)
  81. }
  82. }