ShortcutsConfigView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import Combine
  2. import SwiftUI
  3. import Swinject
  4. import UIKit
  5. extension ShortcutsConfig {
  6. struct RootView: BaseView {
  7. let resolver: Resolver
  8. @StateObject var state = StateModel()
  9. @State private var shouldDisplayHint: Bool = false
  10. @State var hintDetent = PresentationDetent.large
  11. @State var selectedVerboseHint: AnyView?
  12. @State var hintLabel: String?
  13. @State private var decimalPlaceholder: Decimal = 0.0
  14. @State private var booleanPlaceholder: Bool = false
  15. @Environment(\.colorScheme) var colorScheme
  16. private var color: LinearGradient {
  17. colorScheme == .dark ? LinearGradient(
  18. gradient: Gradient(colors: [
  19. Color.bgDarkBlue,
  20. Color.bgDarkerDarkBlue
  21. ]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. :
  26. LinearGradient(
  27. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  28. startPoint: .top,
  29. endPoint: .bottom
  30. )
  31. }
  32. var body: some View {
  33. Form {
  34. Section(
  35. header: Text("Shortcuts Integration"),
  36. content: {
  37. Text(
  38. "Trio lets you create automations using iOS Shortcuts. Go to the Shortcuts app to create new automations."
  39. )
  40. }
  41. ).listRowBackground(Color.chart)
  42. Section {
  43. Button {
  44. UIApplication.shared.open(URL(string: "shortcuts://")!)
  45. }
  46. label: { Label("Open iOS Shortcuts", systemImage: "arrow.triangle.branch").font(.title3).padding() }
  47. .frame(maxWidth: .infinity, alignment: .center)
  48. .buttonStyle(.bordered)
  49. }
  50. .listRowBackground(Color.clear)
  51. SettingInputSection(
  52. decimalValue: $decimalPlaceholder,
  53. booleanValue: $state.allowBolusByShortcuts,
  54. shouldDisplayHint: $shouldDisplayHint,
  55. selectedVerboseHint: Binding(
  56. get: { selectedVerboseHint },
  57. set: {
  58. selectedVerboseHint = $0.map { AnyView($0) }
  59. hintLabel = "Allow Bolusing with Shortcuts"
  60. }
  61. ),
  62. units: state.units,
  63. type: .boolean,
  64. label: "Allow Bolusing with Shortcuts",
  65. miniHint: "Automate boluses using the Shortcuts App",
  66. verboseHint: VStack(spacing: 10) {
  67. Text("Default: OFF").bold()
  68. VStack(alignment: .leading, spacing: 10) {
  69. Text("Enabling this setting allows the iOS Shortcuts App to send bolus commands to Trio.")
  70. Text(
  71. "Disabling this setting will still allow other commands, like Temp Targets, Add Carbs, and Start/End Overrides"
  72. )
  73. }
  74. }
  75. )
  76. }
  77. .sheet(isPresented: $shouldDisplayHint) {
  78. SettingInputHintView(
  79. hintDetent: $hintDetent,
  80. shouldDisplayHint: $shouldDisplayHint,
  81. hintLabel: hintLabel ?? "",
  82. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  83. sheetTitle: "Help"
  84. )
  85. }
  86. .scrollContentBackground(.hidden).background(color)
  87. .onAppear(perform: configureView)
  88. .navigationTitle("Shortcuts")
  89. .navigationBarTitleDisplayMode(.automatic)
  90. }
  91. }
  92. }