From d29aafe08e037584c8098c52f8371e2fedbca391 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 27 Mar 2019 21:04:55 +0100 Subject: [PATCH] Propagate addShortcut delegation in ConnectTo --- .../Scenes/Organizer/ShortcutsAddViewController.swift | 10 ++++++++-- .../Organizer/ShortcutsConnectToViewController.swift | 11 ++++++++--- .../Organizer/ShortcutsEditViewController.swift | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Passepartout-iOS/Scenes/Organizer/ShortcutsAddViewController.swift b/Passepartout-iOS/Scenes/Organizer/ShortcutsAddViewController.swift index 0863df67..58879c08 100644 --- a/Passepartout-iOS/Scenes/Organizer/ShortcutsAddViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/ShortcutsAddViewController.swift @@ -29,9 +29,9 @@ import Passepartout_Core @available(iOS 12, *) protocol ShortcutsAddViewControllerDelegate: class { - func shortcutAddController(_ controller: ShortcutsAddViewController, voiceShortcut: INVoiceShortcut) + func shortcutAddController(_ controller: UIViewController?, voiceShortcut: INVoiceShortcut) - func shortcutAddControllerDidCancel(_ controller: ShortcutsAddViewController) + func shortcutAddControllerDidCancel(_ controller: UIViewController?) } @available(iOS 12, *) @@ -157,6 +157,12 @@ class ShortcutsAddViewController: UITableViewController, INUIAddVoiceShortcutVie } // MARK: Actions + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if let vc = segue.destination as? ShortcutsConnectToViewController { + vc.delegate = delegate + } + } private func addConnect() { guard TransientStore.shared.service.hasProfiles() else { diff --git a/Passepartout-iOS/Scenes/Organizer/ShortcutsConnectToViewController.swift b/Passepartout-iOS/Scenes/Organizer/ShortcutsConnectToViewController.swift index 195d851b..055f0b97 100644 --- a/Passepartout-iOS/Scenes/Organizer/ShortcutsConnectToViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/ShortcutsConnectToViewController.swift @@ -38,6 +38,8 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC private var selectedProfile: ConnectionProfile? + weak var delegate: ShortcutsAddViewControllerDelegate? + // MARK: TableModelHost let model: TableModel = { @@ -187,11 +189,14 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC // MARK: INUIAddVoiceShortcutViewControllerDelegate func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) { - navigationController?.popViewController(animated: true) - dismiss(animated: true, completion: nil) + guard let voiceShortcut = voiceShortcut else { + delegate?.shortcutAddControllerDidCancel(nil) + return + } + delegate?.shortcutAddController(nil, voiceShortcut: voiceShortcut) } func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) { - dismiss(animated: true, completion: nil) + delegate?.shortcutAddControllerDidCancel(nil) } } diff --git a/Passepartout-iOS/Scenes/Organizer/ShortcutsEditViewController.swift b/Passepartout-iOS/Scenes/Organizer/ShortcutsEditViewController.swift index 4e03c944..dbd8d60b 100644 --- a/Passepartout-iOS/Scenes/Organizer/ShortcutsEditViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/ShortcutsEditViewController.swift @@ -195,7 +195,7 @@ class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutV // MARK: ShortcutsAddViewControllerDelegate - func shortcutAddController(_ controller: ShortcutsAddViewController, voiceShortcut: INVoiceShortcut) { + func shortcutAddController(_ controller: UIViewController?, voiceShortcut: INVoiceShortcut) { wrappers?.append(ShortcutWrapper.from(voiceShortcut)) wrappers?.sort() reloadModel() @@ -205,7 +205,7 @@ class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutV dismiss(animated: true, completion: nil) } - func shortcutAddControllerDidCancel(_ controller: ShortcutsAddViewController) { + func shortcutAddControllerDidCancel(_ controller: UIViewController?) { dismiss(animated: true, completion: nil) }