Add shortcut and delegate to manager

This commit is contained in:
Davide De Rosa 2019-03-27 20:52:58 +01:00
parent 0d619ffd62
commit 5ee18071b0
4 changed files with 39 additions and 14 deletions

View File

@ -27,8 +27,16 @@ import UIKit
import IntentsUI
import Passepartout_Core
@available(iOS 12, *)
protocol ShortcutsAddViewControllerDelegate: class {
func shortcutAddController(_ controller: ShortcutsAddViewController, voiceShortcut: INVoiceShortcut)
func shortcutAddControllerDidCancel(_ controller: ShortcutsAddViewController)
}
@available(iOS 12, *)
class ShortcutsAddViewController: UITableViewController, INUIAddVoiceShortcutViewControllerDelegate, TableModelHost {
weak var delegate: ShortcutsAddViewControllerDelegate?
// MARK: TableModel
@ -207,10 +215,14 @@ class ShortcutsAddViewController: UITableViewController, INUIAddVoiceShortcutVie
// MARK: INUIAddVoiceShortcutViewControllerDelegate
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
dismiss(animated: true, completion: nil)
guard let voiceShortcut = voiceShortcut else {
delegate?.shortcutAddControllerDidCancel(self)
return
}
delegate?.shortcutAddController(self, voiceShortcut: voiceShortcut)
}
func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
dismiss(animated: true, completion: nil)
delegate?.shortcutAddControllerDidCancel(self)
}
}

View File

@ -178,10 +178,6 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC
perform(segue: StoryboardSegue.Shortcuts.pickLocationSegueIdentifier)
}
@IBAction private func done() {
dismiss(animated: true, completion: nil)
}
// MARK: ProviderPoolViewControllerDelegate
func providerPoolController(_: ProviderPoolViewController, didSelectPool pool: Pool) {

View File

@ -46,7 +46,7 @@ private struct ShortcutWrapper {
}
@available(iOS 12, *)
class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutViewControllerDelegate, TableModelHost {
class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutViewControllerDelegate, ShortcutsAddViewControllerDelegate, TableModelHost {
private var wrappers: [ShortcutWrapper]?
private var editedIndexPath: IndexPath?
@ -87,6 +87,12 @@ class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutV
// MARK: Actions
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? ShortcutsAddViewController {
vc.delegate = self
}
}
private func addShortcut() {
perform(segue: StoryboardSegue.Shortcuts.shortcutAddSegueIdentifier)
}
@ -174,6 +180,23 @@ class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutV
}
}
// MARK: ShortcutsAddViewControllerDelegate
func shortcutAddController(_ controller: ShortcutsAddViewController, voiceShortcut: INVoiceShortcut) {
// TODO: sort voice shortcuts by?
wrappers?.append(ShortcutWrapper.from(voiceShortcut))
reloadModel()
tableView.reloadData()
navigationController?.popToRootViewController(animated: false)
dismiss(animated: true, completion: nil)
}
func shortcutAddControllerDidCancel(_ controller: ShortcutsAddViewController) {
dismiss(animated: true, completion: nil)
}
// MARK: INUIEditVoiceShortcutViewControllerDelegate
func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) {

View File

@ -96,13 +96,7 @@
<outlet property="delegate" destination="zpj-mS-isI" id="zex-yh-op8"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="kUu-WC-MJQ">
<barButtonItem key="rightBarButtonItem" style="done" systemItem="done" id="m8u-XK-MLx">
<connections>
<action selector="done" destination="zpj-mS-isI" id="f5U-ko-QS3"/>
</connections>
</barButtonItem>
</navigationItem>
<navigationItem key="navigationItem" id="kUu-WC-MJQ"/>
<connections>
<segue destination="bPc-ex-Jwe" kind="show" identifier="PickLocationSegueIdentifier" id="ah9-pc-zoh"/>
</connections>