CalendarEventSettingsRootView.swift 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. private var color: LinearGradient {
  16. colorScheme == .dark ? LinearGradient(
  17. gradient: Gradient(colors: [
  18. Color.bgDarkBlue,
  19. Color.bgDarkerDarkBlue
  20. ]),
  21. startPoint: .top,
  22. endPoint: .bottom
  23. )
  24. :
  25. LinearGradient(
  26. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  27. startPoint: .top,
  28. endPoint: .bottom
  29. )
  30. }
  31. var body: some View {
  32. List {
  33. SettingInputSection(
  34. decimalValue: $decimalPlaceholder,
  35. booleanValue: $state.useCalendar,
  36. shouldDisplayHint: $shouldDisplayHint,
  37. selectedVerboseHint: Binding(
  38. get: { selectedVerboseHint },
  39. set: {
  40. selectedVerboseHint = $0.map { AnyView($0) }
  41. hintLabel = "Create Events in Calendar"
  42. }
  43. ),
  44. units: state.units,
  45. type: .boolean,
  46. label: "Create Events in Calendar",
  47. miniHint: "Uses calendar events to display current data \nDefault: OFF",
  48. verboseHint: VStack(spacing: 10) {
  49. Text("Default: OFF").bold()
  50. VStack(alignment: .leading, spacing: 10) {
  51. Text(
  52. "When enabled, Trio will create a customizable calendar event to keep you notified of your current glucose reading with every successful loop cycle."
  53. )
  54. Text(
  55. "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"
  56. )
  57. Text(
  58. "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."
  59. )
  60. Text("Note: Once a new calendar event is created, the previous event will be deleted.")
  61. }
  62. },
  63. headerText: "Diabetes Data as Calendar Event"
  64. )
  65. if state.calendarIDs.isNotEmpty, state.useCalendar {
  66. Section {
  67. VStack {
  68. Picker("Choose Calendar", selection: $state.currentCalendarID) {
  69. ForEach(state.calendarIDs, id: \.self) {
  70. Text($0).tag($0)
  71. }
  72. }
  73. }
  74. }.listRowBackground(Color.chart)
  75. SettingInputSection(
  76. decimalValue: $decimalPlaceholder,
  77. booleanValue: $state.displayCalendarEmojis,
  78. shouldDisplayHint: $shouldDisplayHint,
  79. selectedVerboseHint: Binding(
  80. get: { selectedVerboseHint },
  81. set: {
  82. selectedVerboseHint = $0.map { AnyView($0) }
  83. hintLabel = "Display Emojis as Labels"
  84. }
  85. ),
  86. units: state.units,
  87. type: .boolean,
  88. label: "Display Emojis as Labels",
  89. miniHint: "Emojis used instead of text for data labels \nDefault: OFF",
  90. verboseHint: VStack(spacing: 10) {
  91. Text("Default: OFF").bold()
  92. VStack(alignment: .leading, spacing: 5) {
  93. Text(
  94. "When enabled, the calendar event created will indicate whether glucose readings are in-range or out-of-range using the following color emojis:"
  95. )
  96. Text("🟢: In-Range")
  97. Text("🟠: Above-Range")
  98. Text("🔴: Below-Range")
  99. }
  100. VStack(alignment: .leading, spacing: 5) {
  101. Text(
  102. "If \"Display IOB and COB\" is also enabled, \"IOB\" and \"COB\" will be replaced with the following emojis:"
  103. )
  104. Text("💉: IOB")
  105. Text("🥨: COB")
  106. }
  107. }
  108. )
  109. SettingInputSection(
  110. decimalValue: $decimalPlaceholder,
  111. booleanValue: $state.displayCalendarIOBandCOB,
  112. shouldDisplayHint: $shouldDisplayHint,
  113. selectedVerboseHint: Binding(
  114. get: { selectedVerboseHint },
  115. set: {
  116. selectedVerboseHint = $0.map { AnyView($0) }
  117. hintLabel = "Display IOB and COB"
  118. }
  119. ),
  120. units: state.units,
  121. type: .boolean,
  122. label: "Display IOB and COB",
  123. miniHint: "Include IOB & COB in the calendar event data \nDefault: OFF",
  124. verboseHint: VStack(spacing: 10) {
  125. Text("Default: OFF").bold()
  126. Text(
  127. "When enabled, Trio will include the current IOB and COB values, along with the current glucose reading, in each calendar event created."
  128. )
  129. }
  130. )
  131. } else if state.useCalendar {
  132. if #available(iOS 17.0, *) {
  133. Text(
  134. "If you are not seeing calendars to choose here, please go to Settings -> Trio -> Calendars and change permissions to \"Full Access\""
  135. ).font(.footnote)
  136. Button("Open Settings") {
  137. // Get the settings URL and open it
  138. if let url = URL(string: UIApplication.openSettingsURLString) {
  139. UIApplication.shared.open(url)
  140. }
  141. }
  142. }
  143. }
  144. }
  145. .sheet(isPresented: $shouldDisplayHint) {
  146. SettingInputHintView(
  147. hintDetent: $hintDetent,
  148. shouldDisplayHint: $shouldDisplayHint,
  149. hintLabel: hintLabel ?? "",
  150. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  151. sheetTitle: "Help"
  152. )
  153. }
  154. .scrollContentBackground(.hidden).background(color)
  155. .onAppear(perform: configureView)
  156. .navigationTitle("Calendar Events")
  157. .navigationBarTitleDisplayMode(.automatic)
  158. }
  159. }
  160. }