Propagate addShortcut delegation in ConnectTo

This commit is contained in:
Davide De Rosa 2019-03-27 21:04:55 +01:00
parent 05ba654b2f
commit d29aafe08e
3 changed files with 18 additions and 7 deletions

View File

@ -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, *)
@ -158,6 +158,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 {
let alert = Macros.alert(

View File

@ -38,6 +38,8 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC
private var selectedProfile: ConnectionProfile?
weak var delegate: ShortcutsAddViewControllerDelegate?
// MARK: TableModelHost
let model: TableModel<SectionType, RowType> = {
@ -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)
}
}

View File

@ -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)
}