NightscoutFetchView.swift 3.6 KB

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