CalendarEventSettingsRootView.swift 5.5 KB

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