Add shortcut and delegate to manager
This commit is contained in:
parent
0d619ffd62
commit
5ee18071b0
|
@ -27,8 +27,16 @@ import UIKit
|
||||||
import IntentsUI
|
import IntentsUI
|
||||||
import Passepartout_Core
|
import Passepartout_Core
|
||||||
|
|
||||||
|
@available(iOS 12, *)
|
||||||
|
protocol ShortcutsAddViewControllerDelegate: class {
|
||||||
|
func shortcutAddController(_ controller: ShortcutsAddViewController, voiceShortcut: INVoiceShortcut)
|
||||||
|
|
||||||
|
func shortcutAddControllerDidCancel(_ controller: ShortcutsAddViewController)
|
||||||
|
}
|
||||||
|
|
||||||
@available(iOS 12, *)
|
@available(iOS 12, *)
|
||||||
class ShortcutsAddViewController: UITableViewController, INUIAddVoiceShortcutViewControllerDelegate, TableModelHost {
|
class ShortcutsAddViewController: UITableViewController, INUIAddVoiceShortcutViewControllerDelegate, TableModelHost {
|
||||||
|
weak var delegate: ShortcutsAddViewControllerDelegate?
|
||||||
|
|
||||||
// MARK: TableModel
|
// MARK: TableModel
|
||||||
|
|
||||||
|
@ -207,10 +215,14 @@ class ShortcutsAddViewController: UITableViewController, INUIAddVoiceShortcutVie
|
||||||
// MARK: INUIAddVoiceShortcutViewControllerDelegate
|
// MARK: INUIAddVoiceShortcutViewControllerDelegate
|
||||||
|
|
||||||
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
|
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) {
|
func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
|
||||||
dismiss(animated: true, completion: nil)
|
delegate?.shortcutAddControllerDidCancel(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,10 +178,6 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC
|
||||||
perform(segue: StoryboardSegue.Shortcuts.pickLocationSegueIdentifier)
|
perform(segue: StoryboardSegue.Shortcuts.pickLocationSegueIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction private func done() {
|
|
||||||
dismiss(animated: true, completion: nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: ProviderPoolViewControllerDelegate
|
// MARK: ProviderPoolViewControllerDelegate
|
||||||
|
|
||||||
func providerPoolController(_: ProviderPoolViewController, didSelectPool pool: Pool) {
|
func providerPoolController(_: ProviderPoolViewController, didSelectPool pool: Pool) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ private struct ShortcutWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(iOS 12, *)
|
@available(iOS 12, *)
|
||||||
class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutViewControllerDelegate, TableModelHost {
|
class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutViewControllerDelegate, ShortcutsAddViewControllerDelegate, TableModelHost {
|
||||||
private var wrappers: [ShortcutWrapper]?
|
private var wrappers: [ShortcutWrapper]?
|
||||||
|
|
||||||
private var editedIndexPath: IndexPath?
|
private var editedIndexPath: IndexPath?
|
||||||
|
@ -87,6 +87,12 @@ class ShortcutsEditViewController: UITableViewController, INUIEditVoiceShortcutV
|
||||||
|
|
||||||
// MARK: Actions
|
// MARK: Actions
|
||||||
|
|
||||||
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||||
|
if let vc = segue.destination as? ShortcutsAddViewController {
|
||||||
|
vc.delegate = self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func addShortcut() {
|
private func addShortcut() {
|
||||||
perform(segue: StoryboardSegue.Shortcuts.shortcutAddSegueIdentifier)
|
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
|
// MARK: INUIEditVoiceShortcutViewControllerDelegate
|
||||||
|
|
||||||
func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) {
|
func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) {
|
||||||
|
|
|
@ -96,13 +96,7 @@
|
||||||
<outlet property="delegate" destination="zpj-mS-isI" id="zex-yh-op8"/>
|
<outlet property="delegate" destination="zpj-mS-isI" id="zex-yh-op8"/>
|
||||||
</connections>
|
</connections>
|
||||||
</tableView>
|
</tableView>
|
||||||
<navigationItem key="navigationItem" id="kUu-WC-MJQ">
|
<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>
|
|
||||||
<connections>
|
<connections>
|
||||||
<segue destination="bPc-ex-Jwe" kind="show" identifier="PickLocationSegueIdentifier" id="ah9-pc-zoh"/>
|
<segue destination="bPc-ex-Jwe" kind="show" identifier="PickLocationSegueIdentifier" id="ah9-pc-zoh"/>
|
||||||
</connections>
|
</connections>
|
||||||
|
|
Loading…
Reference in New Issue