RemoteControlConfig.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import Combine
  2. import SwiftUI
  3. import Swinject
  4. import UIKit
  5. extension RemoteControlConfig {
  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: String?
  12. @State var hintLabel: String?
  13. @State private var decimalPlaceholder: Decimal = 0.0
  14. @State private var isCopied: 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. SettingInputSection(
  35. decimalValue: $decimalPlaceholder,
  36. booleanValue: $state.isTrioRemoteControlEnabled,
  37. shouldDisplayHint: $shouldDisplayHint,
  38. selectedVerboseHint: Binding(
  39. get: { selectedVerboseHint },
  40. set: {
  41. selectedVerboseHint = $0
  42. hintLabel = "Enable Remote Command"
  43. }
  44. ),
  45. units: state.units,
  46. type: .boolean,
  47. label: "Enable Remote Control",
  48. miniHint: "Remote Control allow Trio to receive instructions, such as boluses and temp targets, from LoopFollow.",
  49. verboseHint: "When Remote Control is enabled, you can send boluses, overrides, temporary targets, carbs, and other commands to Trio via push notifications. To ensure security, these commands are protected by a shared secret, which must be entered in LoopFollow.",
  50. headerText: "Trio Remote Control"
  51. )
  52. Section(
  53. header: Text("Shared Secret"),
  54. content: {
  55. TextField("Enter Shared Secret", text: $state.sharedSecret)
  56. .disableAutocorrection(true)
  57. .autocapitalization(.none)
  58. .padding(8)
  59. .background(Color(UIColor.systemGray6))
  60. .cornerRadius(8)
  61. Button(action: {
  62. UIPasteboard.general.string = state.sharedSecret
  63. isCopied = true
  64. }) {
  65. Label("Copy Secret", systemImage: "doc.on.doc")
  66. .frame(maxWidth: .infinity)
  67. }
  68. .buttonStyle(.bordered)
  69. .frame(maxWidth: .infinity)
  70. .alert(isPresented: $isCopied) {
  71. Alert(
  72. title: Text("Copied"),
  73. message: Text("Shared Secret copied to clipboard"),
  74. dismissButton: .default(Text("OK"))
  75. )
  76. }
  77. Button(action: {
  78. state.generateNewSharedSecret()
  79. }) {
  80. Label("Generate Secret", systemImage: "arrow.clockwise")
  81. .frame(maxWidth: .infinity)
  82. }
  83. .buttonStyle(.borderedProminent)
  84. .foregroundColor(.white)
  85. .frame(maxWidth: .infinity)
  86. }
  87. ).listRowBackground(Color.chart)
  88. }
  89. .sheet(isPresented: $shouldDisplayHint) {
  90. SettingInputHintView(
  91. hintDetent: $hintDetent,
  92. shouldDisplayHint: $shouldDisplayHint,
  93. hintLabel: hintLabel ?? "",
  94. hintText: selectedVerboseHint ?? "",
  95. sheetTitle: "Help"
  96. )
  97. }
  98. .scrollContentBackground(.hidden).background(color)
  99. .onAppear(perform: configureView)
  100. .navigationTitle("Remote Control")
  101. .navigationBarTitleDisplayMode(.automatic)
  102. }
  103. }
  104. }