CalendarEventSettingsRootView.swift 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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: String?
  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
  41. hintLabel = "Create Events in Calendar"
  42. }
  43. ),
  44. units: state.units,
  45. type: .boolean,
  46. label: "Create Events in Calendar",
  47. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  48. verboseHint: "Create Calendar Events… bla bla bla",
  49. headerText: "Diabetes Data as Calendar Event"
  50. )
  51. if state.calendarIDs.isNotEmpty, state.useCalendar {
  52. Section {
  53. VStack {
  54. Picker("Choose Calendar", selection: $state.currentCalendarID) {
  55. ForEach(state.calendarIDs, id: \.self) {
  56. Text($0).tag($0)
  57. }
  58. }
  59. }
  60. }.listRowBackground(Color.chart)
  61. SettingInputSection(
  62. decimalValue: $decimalPlaceholder,
  63. booleanValue: $state.displayCalendarEmojis,
  64. shouldDisplayHint: $shouldDisplayHint,
  65. selectedVerboseHint: Binding(
  66. get: { selectedVerboseHint },
  67. set: {
  68. selectedVerboseHint = $0
  69. hintLabel = "Display Emojis as Labels"
  70. }
  71. ),
  72. units: state.units,
  73. type: .boolean,
  74. label: "Display Emojis as Labels",
  75. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  76. verboseHint: "Display Emojis as Labels… bla bla bla"
  77. )
  78. SettingInputSection(
  79. decimalValue: $decimalPlaceholder,
  80. booleanValue: $state.displayCalendarIOBandCOB,
  81. shouldDisplayHint: $shouldDisplayHint,
  82. selectedVerboseHint: Binding(
  83. get: { selectedVerboseHint },
  84. set: {
  85. selectedVerboseHint = $0
  86. hintLabel = "Display IOB and COB"
  87. }
  88. ),
  89. units: state.units,
  90. type: .boolean,
  91. label: "Display IOB and COB",
  92. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  93. verboseHint: "Display IOB and COB… bla bla bla"
  94. )
  95. } else if state.useCalendar {
  96. if #available(iOS 17.0, *) {
  97. Text(
  98. "If you are not seeing calendars to choose here, please go to Settings -> Trio -> Calendars and change permissions to \"Full Access\""
  99. ).font(.footnote)
  100. Button("Open Settings") {
  101. // Get the settings URL and open it
  102. if let url = URL(string: UIApplication.openSettingsURLString) {
  103. UIApplication.shared.open(url)
  104. }
  105. }
  106. }
  107. }
  108. }
  109. .sheet(isPresented: $shouldDisplayHint) {
  110. SettingInputHintView(
  111. hintDetent: $hintDetent,
  112. shouldDisplayHint: $shouldDisplayHint,
  113. hintLabel: hintLabel ?? "",
  114. hintText: selectedVerboseHint ?? "",
  115. sheetTitle: "Help"
  116. )
  117. }
  118. .scrollContentBackground(.hidden).background(color)
  119. .onAppear(perform: configureView)
  120. .navigationTitle("Calendar Events")
  121. .navigationBarTitleDisplayMode(.automatic)
  122. }
  123. }
  124. }