aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-19 01:24:06 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 14:54:05 -0600
commitfc163fc9ff8e6408cfe262d758c402aada920cc1 (patch)
tree237a5a93e9966919b2a8adc8fe2590f0f0ba0791 /WireGuard/WireGuard/UI
parentiOS: Tunnels list: Ability to remove multiple tunnels at a time (diff)
downloadwireguard-apple-fc163fc9ff8e6408cfe262d758c402aada920cc1.tar.xz
wireguard-apple-fc163fc9ff8e6408cfe262d758c402aada920cc1.zip
iOS: Consolidate all showConfirmationAlert()s into one place
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift25
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift19
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift19
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift17
4 files changed, 33 insertions, 47 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift b/WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift
new file mode 100644
index 0000000..8064fff
--- /dev/null
+++ b/WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
+
+import UIKit
+
+class ConfirmationAlertPresenter {
+ static func showConfirmationAlert(message: String, buttonTitle: String, from sourceObject: AnyObject, presentingVC: UIViewController, onConfirmed: @escaping (() -> Void)) {
+ let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { _ in
+ onConfirmed()
+ }
+ let cancelAction = UIAlertAction(title: tr("actionCancel"), style: .cancel)
+ let alert = UIAlertController(title: "", message: message, preferredStyle: .actionSheet)
+ alert.addAction(destroyAction)
+ alert.addAction(cancelAction)
+
+ if let sourceView = sourceObject as? UIView {
+ alert.popoverPresentationController?.sourceView = sourceView
+ alert.popoverPresentationController?.sourceRect = sourceView.bounds
+ } else if let sourceBarButtonItem = sourceObject as? UIBarButtonItem {
+ alert.popoverPresentationController?.barButtonItem = sourceBarButtonItem
+ }
+
+ presentingVC.present(alert, animated: true, completion: nil)
+ }
+}
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
index f198e06..b2dca83 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
@@ -125,21 +125,6 @@ class TunnelDetailTableViewController: UITableViewController {
}
}
- func showConfirmationAlert(message: String, buttonTitle: String, from sourceView: UIView, onConfirmed: @escaping (() -> Void)) {
- let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { _ in
- onConfirmed()
- }
- let cancelAction = UIAlertAction(title: tr("actionCancel"), style: .cancel)
- let alert = UIAlertController(title: "", message: message, preferredStyle: .actionSheet)
- alert.addAction(destroyAction)
- alert.addAction(cancelAction)
-
- alert.popoverPresentationController?.sourceView = sourceView
- alert.popoverPresentationController?.sourceRect = sourceView.bounds
-
- present(alert, animated: true, completion: nil)
- }
-
func startUpdatingRuntimeConfiguration() {
reloadRuntimeConfiguration()
reloadRuntimeConfigurationTimer?.invalidate()
@@ -435,7 +420,9 @@ extension TunnelDetailTableViewController {
cell.hasDestructiveAction = true
cell.onTapped = { [weak self] in
guard let self = self else { return }
- self.showConfirmationAlert(message: tr("deleteTunnelConfirmationAlertMessage"), buttonTitle: tr("deleteTunnelConfirmationAlertButtonTitle"), from: cell) { [weak self] in
+ ConfirmationAlertPresenter.showConfirmationAlert(message: tr("deleteTunnelConfirmationAlertMessage"),
+ buttonTitle: tr("deleteTunnelConfirmationAlertButtonTitle"),
+ from: cell, presentingVC: self) { [weak self] in
guard let self = self else { return }
self.tunnelsManager.remove(tunnel: self.tunnel) { error in
if error != nil {
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
index 7d360d1..6452bfb 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
@@ -311,7 +311,9 @@ extension TunnelEditTableViewController {
cell.hasDestructiveAction = true
cell.onTapped = { [weak self, weak peerData] in
guard let self = self, let peerData = peerData else { return }
- self.showConfirmationAlert(message: tr("deletePeerConfirmationAlertMessage"), buttonTitle: tr("deletePeerConfirmationAlertButtonTitle"), from: cell) { [weak self] in
+ ConfirmationAlertPresenter.showConfirmationAlert(message: tr("deletePeerConfirmationAlertMessage"),
+ buttonTitle: tr("deletePeerConfirmationAlertButtonTitle"),
+ from: cell, presentingVC: self) { [weak self] in
guard let self = self else { return }
let removedSectionIndices = self.deletePeer(peer: peerData)
let shouldShowExcludePrivateIPs = (self.tunnelViewModel.peersData.count == 1 && self.tunnelViewModel.peersData[0].shouldAllowExcludePrivateIPsControl)
@@ -461,21 +463,6 @@ extension TunnelEditTableViewController {
loadSections()
return IndexSet(integer: interfaceFieldsBySection.count + peer.index)
}
-
- func showConfirmationAlert(message: String, buttonTitle: String, from sourceView: UIView, onConfirmed: @escaping (() -> Void)) {
- let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { _ in
- onConfirmed()
- }
- let cancelAction = UIAlertAction(title: tr("actionCancel"), style: .cancel)
- let alert = UIAlertController(title: "", message: message, preferredStyle: .actionSheet)
- alert.addAction(destroyAction)
- alert.addAction(cancelAction)
-
- alert.popoverPresentationController?.sourceView = sourceView
- alert.popoverPresentationController?.sourceRect = sourceView.bounds
-
- present(alert, animated: true, completion: nil)
- }
}
extension TunnelEditTableViewController {
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
index c09bb34..d54d7a1 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
@@ -238,7 +238,8 @@ class TunnelsListTableViewController: UIViewController {
tr(format: "deleteTunnelConfirmationAlertButtonMessage (%d)", selectedTunnels.count) :
tr(format: "deleteTunnelsConfirmationAlertButtonMessage (%d)", selectedTunnels.count)
let title = tr("deleteTunnelsConfirmationAlertButtonTitle")
- self.showConfirmationAlert(message: message, buttonTitle: title, from: sender) { [weak self] in
+ ConfirmationAlertPresenter.showConfirmationAlert(message: message, buttonTitle: title,
+ from: sender, presentingVC: self) { [weak self] in
self?.tunnelsManager?.removeMultiple(tunnels: selectedTunnels) { [weak self] error in
guard let self = self else { return }
if let error = error {
@@ -250,20 +251,6 @@ class TunnelsListTableViewController: UIViewController {
}
}
}
-
- func showConfirmationAlert(message: String, buttonTitle: String, from barButtonItem: UIBarButtonItem, onConfirmed: @escaping (() -> Void)) {
- let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { _ in
- onConfirmed()
- }
- let cancelAction = UIAlertAction(title: tr("actionCancel"), style: .cancel)
- let alert = UIAlertController(title: "", message: message, preferredStyle: .actionSheet)
- alert.addAction(destroyAction)
- alert.addAction(cancelAction)
-
- alert.popoverPresentationController?.barButtonItem = barButtonItem
-
- present(alert, animated: true, completion: nil)
- }
}
extension TunnelsListTableViewController: UIDocumentPickerDelegate {