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, *) @available(iOS 12, *)
protocol ShortcutsAddViewControllerDelegate: class { 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, *) @available(iOS 12, *)
@ -158,6 +158,12 @@ class ShortcutsAddViewController: UITableViewController, INUIAddVoiceShortcutVie
// MARK: Actions // MARK: Actions
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? ShortcutsConnectToViewController {
vc.delegate = delegate
}
}
private func addConnect() { private func addConnect() {
guard TransientStore.shared.service.hasProfiles() else { guard TransientStore.shared.service.hasProfiles() else {
let alert = Macros.alert( let alert = Macros.alert(

View File

@ -38,6 +38,8 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC
private var selectedProfile: ConnectionProfile? private var selectedProfile: ConnectionProfile?
weak var delegate: ShortcutsAddViewControllerDelegate?
// MARK: TableModelHost // MARK: TableModelHost
let model: TableModel<SectionType, RowType> = { let model: TableModel<SectionType, RowType> = {
@ -187,11 +189,14 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC
// MARK: INUIAddVoiceShortcutViewControllerDelegate // MARK: INUIAddVoiceShortcutViewControllerDelegate
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) { func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
navigationController?.popViewController(animated: true) guard let voiceShortcut = voiceShortcut else {
dismiss(animated: true, completion: nil) delegate?.shortcutAddControllerDidCancel(nil)
return
}
delegate?.shortcutAddController(nil, voiceShortcut: voiceShortcut)
} }
func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) { func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
dismiss(animated: true, completion: nil) delegate?.shortcutAddControllerDidCancel(nil)
} }
} }

View File

@ -195,7 +195,7 @@ class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutV
// MARK: ShortcutsAddViewControllerDelegate // MARK: ShortcutsAddViewControllerDelegate
func shortcutAddController(_ controller: ShortcutsAddViewController, voiceShortcut: INVoiceShortcut) { func shortcutAddController(_ controller: UIViewController?, voiceShortcut: INVoiceShortcut) {
wrappers?.append(ShortcutWrapper.from(voiceShortcut)) wrappers?.append(ShortcutWrapper.from(voiceShortcut))
wrappers?.sort() wrappers?.sort()
reloadModel() reloadModel()
@ -205,7 +205,7 @@ class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutV
dismiss(animated: true, completion: nil) dismiss(animated: true, completion: nil)
} }
func shortcutAddControllerDidCancel(_ controller: ShortcutsAddViewController) { func shortcutAddControllerDidCancel(_ controller: UIViewController?) {
dismiss(animated: true, completion: nil) dismiss(animated: true, completion: nil)
} }