| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import Combine
- import SwiftUI
- import Swinject
- import UIKit
- extension RemoteControlConfig {
- struct RootView: BaseView {
- let resolver: Resolver
- @StateObject var state = StateModel()
- @State private var shouldDisplayHint: Bool = false
- @State var hintDetent = PresentationDetent.large
- @State var selectedVerboseHint: String?
- @State var hintLabel: String?
- @State private var decimalPlaceholder: Decimal = 0.0
- @State private var isCopied: Bool = false
- @Environment(\.colorScheme) var colorScheme
- private var color: LinearGradient {
- colorScheme == .dark ? LinearGradient(
- gradient: Gradient(colors: [
- Color.bgDarkBlue,
- Color.bgDarkerDarkBlue
- ]),
- startPoint: .top,
- endPoint: .bottom
- )
- :
- LinearGradient(
- gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
- startPoint: .top,
- endPoint: .bottom
- )
- }
- var body: some View {
- Form {
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.isTrioRemoteControlEnabled,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Enable Remote Command"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Enable Remote Control",
- miniHint: "Remote Control allow Trio to receive instructions, such as boluses and temp targets, from LoopFollow.",
- 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.",
- headerText: "Trio Remote Control"
- )
- Section(
- header: Text("Shared Secret"),
- content: {
- TextField("Enter Shared Secret", text: $state.sharedSecret)
- .disableAutocorrection(true)
- .autocapitalization(.none)
- .padding(8)
- .background(Color(UIColor.systemGray6))
- .cornerRadius(8)
- Button(action: {
- UIPasteboard.general.string = state.sharedSecret
- isCopied = true
- }) {
- Label("Copy Secret", systemImage: "doc.on.doc")
- .frame(maxWidth: .infinity)
- }
- .buttonStyle(.bordered)
- .frame(maxWidth: .infinity)
- .alert(isPresented: $isCopied) {
- Alert(
- title: Text("Copied"),
- message: Text("Shared Secret copied to clipboard"),
- dismissButton: .default(Text("OK"))
- )
- }
- Button(action: {
- state.generateNewSharedSecret()
- }) {
- Label("Generate Secret", systemImage: "arrow.clockwise")
- .frame(maxWidth: .infinity)
- }
- .buttonStyle(.borderedProminent)
- .foregroundColor(.white)
- .frame(maxWidth: .infinity)
- }
- ).listRowBackground(Color.chart)
- }
- .sheet(isPresented: $shouldDisplayHint) {
- SettingInputHintView(
- hintDetent: $hintDetent,
- shouldDisplayHint: $shouldDisplayHint,
- hintLabel: hintLabel ?? "",
- hintText: selectedVerboseHint ?? "",
- sheetTitle: "Help"
- )
- }
- .scrollContentBackground(.hidden).background(color)
- .onAppear(perform: configureView)
- .navigationTitle("Remote Control")
- .navigationBarTitleDisplayMode(.automatic)
- }
- }
- }
|