CalendarEventSettingsRootView.swift 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import SwiftUI
  2. import Swinject
  3. extension CalendarEventSettings {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @State private var shouldDisplayHint: Bool = false
  8. @State var hintDetent = PresentationDetent.large
  9. @State var selectedVerboseHint: AnyView?
  10. @State var hintLabel: String?
  11. @State private var decimalPlaceholder: Decimal = 0.0
  12. @State private var booleanPlaceholder: Bool = false
  13. @Environment(\.colorScheme) var colorScheme
  14. @EnvironmentObject var appIcons: Icons
  15. @Environment(AppState.self) var appState
  16. var body: some View {
  17. List {
  18. SettingInputSection(
  19. decimalValue: $decimalPlaceholder,
  20. booleanValue: $state.useCalendar,
  21. shouldDisplayHint: $shouldDisplayHint,
  22. selectedVerboseHint: Binding(
  23. get: { selectedVerboseHint },
  24. set: {
  25. selectedVerboseHint = $0.map { AnyView($0) }
  26. hintLabel = "Create Events in Calendar"
  27. }
  28. ),
  29. units: state.units,
  30. type: .boolean,
  31. label: "Create Events in Calendar",
  32. miniHint: "Uses calendar events to display current data.",
  33. verboseHint:
  34. VStack(alignment: .leading, spacing: 10) {
  35. Text("Default: OFF").bold()
  36. Text(
  37. "When enabled, Trio will create a customizable calendar event to keep you notified of your current glucose reading with every successful loop cycle."
  38. )
  39. Text(
  40. "This is useful if you use CarPlay or a variety of other external services that limit the view of most apps, but allows the calendar app"
  41. )
  42. Text(
  43. "Once enabled, the available customizations will appear. You can customize with the calendar of your choosing, use of emoji labels, and the inclusion of IOB & COB data."
  44. )
  45. Text("Note: Once a new calendar event is created, the previous event will be deleted.")
  46. },
  47. headerText: "Diabetes Data as Calendar Event"
  48. )
  49. if state.calendarIDs.isNotEmpty, state.useCalendar {
  50. Section {
  51. VStack {
  52. Picker("Choose Calendar", selection: $state.currentCalendarID) {
  53. ForEach(state.calendarIDs, id: \.self) {
  54. Text($0).tag($0)
  55. }
  56. }
  57. }
  58. }.listRowBackground(Color.chart)
  59. SettingInputSection(
  60. decimalValue: $decimalPlaceholder,
  61. booleanValue: $state.displayCalendarEmojis,
  62. shouldDisplayHint: $shouldDisplayHint,
  63. selectedVerboseHint: Binding(
  64. get: { selectedVerboseHint },
  65. set: {
  66. selectedVerboseHint = $0.map { AnyView($0) }
  67. hintLabel = "Display Emojis as Labels"
  68. }
  69. ),
  70. units: state.units,
  71. type: .boolean,
  72. label: "Display Emojis as Labels",
  73. miniHint: "Emojis used instead of text for data labels.",
  74. verboseHint: VStack(alignment: .leading, spacing: 10) {
  75. Text("Default: OFF").bold()
  76. VStack(alignment: .leading, spacing: 5) {
  77. Text(
  78. "When enabled, the calendar event created will indicate whether glucose readings are in-range or out-of-range using the following color emojis:"
  79. )
  80. Text("🟢: In-Range")
  81. Text("🟠: Above-Range")
  82. Text("🔴: Below-Range")
  83. }
  84. VStack(alignment: .leading, spacing: 5) {
  85. Text(
  86. "If \"Display IOB and COB\" is also enabled, \"IOB\" and \"COB\" will be replaced with the following emojis:"
  87. )
  88. Text("💉: IOB")
  89. Text("🥨: COB")
  90. }
  91. }
  92. )
  93. SettingInputSection(
  94. decimalValue: $decimalPlaceholder,
  95. booleanValue: $state.displayCalendarIOBandCOB,
  96. shouldDisplayHint: $shouldDisplayHint,
  97. selectedVerboseHint: Binding(
  98. get: { selectedVerboseHint },
  99. set: {
  100. selectedVerboseHint = $0.map { AnyView($0) }
  101. hintLabel = "Display IOB and COB"
  102. }
  103. ),
  104. units: state.units,
  105. type: .boolean,
  106. label: "Display IOB and COB",
  107. miniHint: "Include IOB & COB in the calendar event data.",
  108. verboseHint: VStack(alignment: .leading, spacing: 10) {
  109. Text("Default: OFF").bold()
  110. Text(
  111. "When enabled, Trio will include the current IOB and COB values, along with the current glucose reading, in each calendar event created."
  112. )
  113. }
  114. )
  115. } else if state.useCalendar {
  116. if #available(iOS 17.0, *) {
  117. Text(
  118. "If you are not seeing calendars to choose here, please go to Settings -> Trio -> Calendars and change permissions to \"Full Access\""
  119. ).font(.footnote)
  120. Button("Open Settings") {
  121. // Get the settings URL and open it
  122. if let url = URL(string: UIApplication.openSettingsURLString) {
  123. UIApplication.shared.open(url)
  124. }
  125. }
  126. }
  127. }
  128. }
  129. .listSectionSpacing(sectionSpacing)
  130. .sheet(isPresented: $shouldDisplayHint) {
  131. SettingInputHintView(
  132. hintDetent: $hintDetent,
  133. shouldDisplayHint: $shouldDisplayHint,
  134. hintLabel: hintLabel ?? "",
  135. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  136. sheetTitle: "Help"
  137. )
  138. }
  139. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  140. .onAppear(perform: configureView)
  141. .navigationTitle("Calendar Events")
  142. .navigationBarTitleDisplayMode(.automatic)
  143. }
  144. }
  145. }