| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import SwiftUI
- import Swinject
- extension CalendarEventSettings {
- struct RootView: BaseView {
- let resolver: Resolver
- @StateObject var state = StateModel()
- @State private var shouldDisplayHint: Bool = false
- @State var hintDetent = PresentationDetent.large
- @State var selectedVerboseHint: AnyView?
- @State var hintLabel: String?
- @State private var decimalPlaceholder: Decimal = 0.0
- @State private var booleanPlaceholder: Bool = false
- @Environment(\.colorScheme) var colorScheme
- @EnvironmentObject var appIcons: Icons
- @Environment(AppState.self) var appState
- var body: some View {
- List {
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.useCalendar,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0.map { AnyView($0) }
- hintLabel = "Create Events in Calendar"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Create Events in Calendar",
- miniHint: "Use calendar events to display current data.",
- verboseHint:
- VStack(alignment: .leading, spacing: 10) {
- Text("Default: OFF").bold()
- Text(
- "When enabled, Trio will create a customizable calendar event to keep you notified of your current glucose reading with every successful loop cycle."
- )
- Text(
- "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"
- )
- Text(
- "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."
- )
- Text("Note: Once a new calendar event is created, the previous event will be deleted.")
- },
- headerText: "Diabetes Data as Calendar Event"
- )
- if state.calendarIDs.isNotEmpty, state.useCalendar {
- Section {
- VStack {
- Picker("Choose Calendar", selection: $state.currentCalendarID) {
- ForEach(state.calendarIDs, id: \.self) {
- Text($0).tag($0)
- }
- }
- }
- }.listRowBackground(Color.chart)
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.displayCalendarEmojis,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0.map { AnyView($0) }
- hintLabel = "Display Emojis as Labels"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Display Emojis as Labels",
- miniHint: "Use emojis for calendar events. See hint for more details.",
- verboseHint: VStack(alignment: .leading, spacing: 10) {
- Text("Default: OFF").bold()
- VStack(alignment: .leading, spacing: 5) {
- Text(
- "When enabled, the calendar event created will indicate whether glucose readings are in-range or out-of-range using the following color emojis:"
- )
- Text("🟢: In-Range")
- Text("🟠: Above-Range")
- Text("🔴: Below-Range")
- }
- VStack(alignment: .leading, spacing: 5) {
- Text(
- "If \"Display IOB and COB\" is also enabled, \"IOB\" and \"COB\" will be replaced with the following emojis:"
- )
- Text("💉: IOB")
- Text("🥨: COB")
- }
- }
- )
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.displayCalendarIOBandCOB,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0.map { AnyView($0) }
- hintLabel = "Display IOB and COB"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Display IOB and COB",
- miniHint: "Include IOB & COB in the calendar event data.",
- verboseHint: VStack(alignment: .leading, spacing: 10) {
- Text("Default: OFF").bold()
- Text(
- "When enabled, Trio will include the current IOB and COB values, along with the current glucose reading, in each calendar event created."
- )
- }
- )
- } else if state.useCalendar {
- if #available(iOS 17.0, *) {
- Text(
- "If you are not seeing calendars to choose here, please go to Settings -> Trio -> Calendars and change permissions to \"Full Access\""
- ).font(.footnote)
- Button("Open Settings") {
- // Get the settings URL and open it
- if let url = URL(string: UIApplication.openSettingsURLString) {
- UIApplication.shared.open(url)
- }
- }
- }
- }
- }
- .listSectionSpacing(sectionSpacing)
- .sheet(isPresented: $shouldDisplayHint) {
- SettingInputHintView(
- hintDetent: $hintDetent,
- shouldDisplayHint: $shouldDisplayHint,
- hintLabel: hintLabel ?? "",
- hintText: selectedVerboseHint ?? AnyView(EmptyView()),
- sheetTitle: "Help"
- )
- }
- .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
- .onAppear(perform: configureView)
- .navigationTitle("Calendar Events")
- .navigationBarTitleDisplayMode(.automatic)
- }
- }
- }
|