|
|
@@ -6,52 +6,86 @@ import UIKit
|
|
|
extension ShortcutsConfig {
|
|
|
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 booleanPlaceholder: 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 {
|
|
|
- Section(header: Text("Shortcuts", tableName: "ShortcutsDetail")) {
|
|
|
- Text(
|
|
|
- "The application lets you create automations using shortcuts. Go to the Shortcuts application to create new automations.",
|
|
|
- tableName: "ShortcutsDetail"
|
|
|
- )
|
|
|
- Button(String(localized: "Open Shortcuts app", table: "ShortcutsDetail")) {
|
|
|
- openShortcutsApp()
|
|
|
+ Section(
|
|
|
+ header: Text("Shortcuts Integration"),
|
|
|
+ content: {
|
|
|
+ Text(
|
|
|
+ "Trio lets you create automations using iOS Shortcuts. Go to the Shortcuts app to create new automations."
|
|
|
+ )
|
|
|
}
|
|
|
- }
|
|
|
+ ).listRowBackground(Color.chart)
|
|
|
|
|
|
- Section(header: Text("Options", tableName: "ShorcutsDetail")) {
|
|
|
- Toggle(
|
|
|
- String(localized: "Allow bolusing with Shortcuts", table: "ShortcutsDetail"),
|
|
|
- isOn: $state.allowBolusByShortcuts
|
|
|
- )
|
|
|
+ Section {
|
|
|
+ Button {
|
|
|
+ UIApplication.shared.open(URL(string: "shortcuts://")!)
|
|
|
+ }
|
|
|
+ label: { Label("Open iOS Shortcuts", systemImage: "arrow.triangle.branch").font(.title3).padding() }
|
|
|
+ .frame(maxWidth: .infinity, alignment: .center)
|
|
|
+ .buttonStyle(.bordered)
|
|
|
}
|
|
|
+ .listRowBackground(Color.clear)
|
|
|
+
|
|
|
+ SettingInputSection(
|
|
|
+ decimalValue: $decimalPlaceholder,
|
|
|
+ booleanValue: $state.allowBolusByShortcuts,
|
|
|
+ shouldDisplayHint: $shouldDisplayHint,
|
|
|
+ selectedVerboseHint: Binding(
|
|
|
+ get: { selectedVerboseHint },
|
|
|
+ set: {
|
|
|
+ selectedVerboseHint = $0
|
|
|
+ hintLabel = "Allow Bolusing with Shortcuts"
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ type: .boolean,
|
|
|
+ label: "Allow Bolusing with Shortcuts",
|
|
|
+ miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
|
|
|
+ verboseHint: "Allow Bolusing with Shortcuts… bla bla bla"
|
|
|
+ )
|
|
|
+ }
|
|
|
+ .sheet(isPresented: $shouldDisplayHint) {
|
|
|
+ SettingInputHintView(
|
|
|
+ hintDetent: $hintDetent,
|
|
|
+ shouldDisplayHint: $shouldDisplayHint,
|
|
|
+ hintLabel: hintLabel ?? "",
|
|
|
+ hintText: selectedVerboseHint ?? "",
|
|
|
+ sheetTitle: "Help"
|
|
|
+ )
|
|
|
}
|
|
|
+ .scrollContentBackground(.hidden).background(color)
|
|
|
.onAppear(perform: configureView)
|
|
|
- .navigationTitle(String(localized: "Shortcuts config", table: "ShortcutsDetail"))
|
|
|
+ .navigationTitle("Shortcuts")
|
|
|
.navigationBarTitleDisplayMode(.automatic)
|
|
|
}
|
|
|
-
|
|
|
- private func openShortcutsApp() {
|
|
|
- let shortcutsURL = URL(string: "shortcuts://")!
|
|
|
-
|
|
|
- if UIApplication.shared.canOpenURL(shortcutsURL) {
|
|
|
- UIApplication.shared.open(shortcutsURL, options: [:], completionHandler: { success in
|
|
|
- if !success {
|
|
|
- state.router.alertMessage
|
|
|
- .send(MessageContent(
|
|
|
- content: String(localized: "Unable to open the app", table: "ShortcutsDetail"),
|
|
|
- type: .warning
|
|
|
- ))
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- router.alertMessage
|
|
|
- .send(MessageContent(
|
|
|
- content: String(localized: "Unable to open the app", table: "ShortcutsDetail"),
|
|
|
- type: .warning
|
|
|
- ))
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|