Add basic cells for any possible shortcut
This commit is contained in:
parent
1c103c639d
commit
8f3d2f0b15
|
@ -27,8 +27,28 @@ import UIKit
|
|||
import IntentsUI
|
||||
import Passepartout_Core
|
||||
|
||||
class ShortcutsViewController: UITableViewController {
|
||||
class ShortcutsViewController: UITableViewController, TableModelHost {
|
||||
|
||||
// MARK: TableModel
|
||||
|
||||
let model: TableModel<SectionType, RowType> = {
|
||||
let model: TableModel<SectionType, RowType> = TableModel()
|
||||
model.add(.shortcutCreation)
|
||||
model.set([
|
||||
.connect,
|
||||
.enableVPN,
|
||||
.disableVPN,
|
||||
.trustWiFi,
|
||||
.untrustWiFi,
|
||||
.trustCellular,
|
||||
.untrustCellular
|
||||
], in: .shortcutCreation)
|
||||
return model
|
||||
}()
|
||||
|
||||
func reloadModel() {
|
||||
}
|
||||
|
||||
// MARK: UIViewController
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
@ -37,18 +57,151 @@ class ShortcutsViewController: UITableViewController {
|
|||
title = L10n.Organizer.Cells.SiriShortcuts.caption
|
||||
// itemNext.title = L10n.Global.next
|
||||
}
|
||||
}
|
||||
|
||||
extension ShortcutsViewController {
|
||||
enum SectionType {
|
||||
case shortcutCreation
|
||||
}
|
||||
|
||||
enum RowType {
|
||||
case connect // host or provider+location
|
||||
|
||||
case enableVPN
|
||||
|
||||
case disableVPN
|
||||
|
||||
case trustWiFi
|
||||
|
||||
case untrustWiFi
|
||||
|
||||
case trustCellular
|
||||
|
||||
case untrustCellular
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return model.count(for: section)
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
||||
switch model.row(at: indexPath) {
|
||||
case .connect:
|
||||
cell.leftText = L10n.Shortcuts.Cells.Connect.caption
|
||||
|
||||
case .enableVPN:
|
||||
cell.leftText = L10n.Shortcuts.Cells.EnableVpn.caption
|
||||
|
||||
case .disableVPN:
|
||||
cell.leftText = L10n.Shortcuts.Cells.DisableVpn.caption
|
||||
|
||||
case .trustWiFi:
|
||||
cell.leftText = L10n.Shortcuts.Cells.TrustWifi.caption
|
||||
|
||||
case .untrustWiFi:
|
||||
cell.leftText = L10n.Shortcuts.Cells.UntrustWifi.caption
|
||||
|
||||
case .trustCellular:
|
||||
cell.leftText = L10n.Shortcuts.Cells.TrustCellular.caption
|
||||
|
||||
case .untrustCellular:
|
||||
cell.leftText = L10n.Shortcuts.Cells.UntrustCellular.caption
|
||||
}
|
||||
cell.apply(Theme.current)
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
guard #available(iOS 12, *) else {
|
||||
return
|
||||
}
|
||||
switch model.row(at: indexPath) {
|
||||
case .connect:
|
||||
addConnect()
|
||||
|
||||
case .enableVPN:
|
||||
addEnable()
|
||||
|
||||
case .disableVPN:
|
||||
addDisable()
|
||||
|
||||
case .trustWiFi:
|
||||
addTrustWiFi()
|
||||
|
||||
case .untrustWiFi:
|
||||
addUntrustWiFi()
|
||||
|
||||
case .trustCellular:
|
||||
addTrustCellular()
|
||||
|
||||
case .untrustCellular:
|
||||
addUntrustCellular()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
@available(iOS 12, *)
|
||||
extension ShortcutsViewController {
|
||||
private func addConnect() {
|
||||
// FIXME: show hosts and providers, host delegates selection, provider requires location
|
||||
let intent = ConnectVPNIntent()
|
||||
guard let profileKey = TransientStore.shared.service.activeProfileKey else {
|
||||
return
|
||||
}
|
||||
intent.context = profileKey.context.rawValue
|
||||
intent.profileId = profileKey.id
|
||||
addShortcut(with: intent)
|
||||
}
|
||||
|
||||
private func addEnable() {
|
||||
addShortcut(with: EnableVPNIntent())
|
||||
}
|
||||
|
||||
private func addDisable() {
|
||||
addShortcut(with: DisableVPNIntent())
|
||||
}
|
||||
|
||||
private func addTrustWiFi() {
|
||||
addShortcut(with: TrustCurrentNetworkIntent())
|
||||
}
|
||||
|
||||
private func addUntrustWiFi() {
|
||||
addShortcut(with: UntrustCurrentNetworkIntent())
|
||||
}
|
||||
|
||||
private func addTrustCellular() {
|
||||
addShortcut(with: TrustCellularNetworkIntent())
|
||||
}
|
||||
|
||||
private func addUntrustCellular() {
|
||||
addShortcut(with: UntrustCellularNetworkIntent())
|
||||
}
|
||||
|
||||
private func addShortcut(with intent: INIntent) {
|
||||
guard let shortcut = INShortcut(intent: intent) else {
|
||||
return
|
||||
}
|
||||
let vc = INUIAddVoiceShortcutViewController(shortcut: shortcut)
|
||||
vc.delegate = self
|
||||
present(vc, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
@IBAction private func close() {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
extension ShortcutsViewController {
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return 3
|
||||
@available(iOS 12, *)
|
||||
extension ShortcutsViewController: INUIAddVoiceShortcutViewControllerDelegate {
|
||||
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
|
||||
tableView.reloadData()
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
return UITableViewCell()
|
||||
func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,13 +216,13 @@
|
|||
<scene sceneID="0zM-zA-ZTU">
|
||||
<objects>
|
||||
<tableViewController id="c0p-pg-Arz" customClass="ImportedHostsViewController" customModule="Passepartout" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="j8e-Ab-2SM">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="j8e-Ab-2SM">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="SettingTableViewCell" textLabel="h2k-uQ-JBT" detailTextLabel="Tnk-4u-fB2" style="IBUITableViewCellStyleValue1" id="4dG-dn-eeq" customClass="SettingTableViewCell" customModule="Passepartout" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
|
||||
<rect key="frame" x="0.0" y="55.5" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="4dG-dn-eeq" id="c48-Fg-ve4">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
|
||||
|
|
|
@ -192,6 +192,14 @@
|
|||
"issue_reporter.email.body" = "Hi,\n\n%@\n\n%@\n\nRegards";
|
||||
"issue_reporter.email.description" = "description of the issue:";
|
||||
|
||||
"shortcuts.cells.connect.caption" = "Connect to";
|
||||
"shortcuts.cells.enable_vpn.caption" = "Enable VPN";
|
||||
"shortcuts.cells.disable_vpn.caption" = "Disable VPN";
|
||||
"shortcuts.cells.trust_wifi.caption" = "Trust current Wi-Fi";
|
||||
"shortcuts.cells.untrust_wifi.caption" = "Untrust current Wi-Fi";
|
||||
"shortcuts.cells.trust_cellular.caption" = "Trust cellular network";
|
||||
"shortcuts.cells.untrust_cellular.caption" = "Untrust cellular network";
|
||||
|
||||
"about.title" = "About";
|
||||
"about.sections.web.header" = "Web";
|
||||
"about.sections.share.header" = "Share";
|
||||
|
|
|
@ -650,6 +650,39 @@ public enum L10n {
|
|||
public static let message = L10n.tr("Localizable", "share.message")
|
||||
}
|
||||
|
||||
public enum Shortcuts {
|
||||
public enum Cells {
|
||||
public enum Connect {
|
||||
/// Connect to
|
||||
public static let caption = L10n.tr("Localizable", "shortcuts.cells.connect.caption")
|
||||
}
|
||||
public enum DisableVpn {
|
||||
/// Disable VPN
|
||||
public static let caption = L10n.tr("Localizable", "shortcuts.cells.disable_vpn.caption")
|
||||
}
|
||||
public enum EnableVpn {
|
||||
/// Enable VPN
|
||||
public static let caption = L10n.tr("Localizable", "shortcuts.cells.enable_vpn.caption")
|
||||
}
|
||||
public enum TrustCellular {
|
||||
/// Trust cellular network
|
||||
public static let caption = L10n.tr("Localizable", "shortcuts.cells.trust_cellular.caption")
|
||||
}
|
||||
public enum TrustWifi {
|
||||
/// Trust current Wi-Fi
|
||||
public static let caption = L10n.tr("Localizable", "shortcuts.cells.trust_wifi.caption")
|
||||
}
|
||||
public enum UntrustCellular {
|
||||
/// Untrust cellular network
|
||||
public static let caption = L10n.tr("Localizable", "shortcuts.cells.untrust_cellular.caption")
|
||||
}
|
||||
public enum UntrustWifi {
|
||||
/// Untrust current Wi-Fi
|
||||
public static let caption = L10n.tr("Localizable", "shortcuts.cells.untrust_wifi.caption")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Version {
|
||||
/// Version
|
||||
public static let title = L10n.tr("Localizable", "version.title")
|
||||
|
|
Loading…
Reference in New Issue