CalendarEventSettingsRootView.swift 5.1 KB

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