summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ios/MullvadVPN/AccountViewController.swift8
-rw-r--r--ios/MullvadVPN/AppDelegate.swift36
-rw-r--r--ios/MullvadVPN/LoginViewController.swift14
-rw-r--r--ios/MullvadVPN/RootContainerViewController.swift31
-rw-r--r--ios/MullvadVPN/SettingsViewController.swift27
5 files changed, 83 insertions, 33 deletions
diff --git a/ios/MullvadVPN/AccountViewController.swift b/ios/MullvadVPN/AccountViewController.swift
index 0d680f5c02..03263ff6f1 100644
--- a/ios/MullvadVPN/AccountViewController.swift
+++ b/ios/MullvadVPN/AccountViewController.swift
@@ -10,6 +10,10 @@ import StoreKit
import UIKit
import Logging
+protocol AccountViewControllerDelegate: class {
+ func accountViewControllerDidLogout(_ controller: AccountViewController)
+}
+
class AccountViewController: UIViewController, AppStorePaymentObserver {
@IBOutlet var accountTokenButton: UIButton!
@@ -26,7 +30,7 @@ class AccountViewController: UIViewController, AppStorePaymentObserver {
private let alertPresenter = AlertPresenter()
private let logger = Logger(label: "AccountViewController")
- var didFinishLogout: (() -> Void)?
+ weak var delegate: AccountViewControllerDelegate?
private lazy var purchaseButtonInteractionRestriction =
UserInterfaceInteractionRestriction { [weak self] (enableUserInteraction, _) in
@@ -254,7 +258,7 @@ class AccountViewController: UIViewController, AppStorePaymentObserver {
self.alertPresenter.enqueue(errorAlertController, presentingController: self)
case .success:
- self.didFinishLogout?()
+ self.delegate?.accountViewControllerDidLogout(self)
}
}
}
diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift
index d54ac731fc..9293388016 100644
--- a/ios/MullvadVPN/AppDelegate.swift
+++ b/ios/MullvadVPN/AppDelegate.swift
@@ -16,6 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
+ var rootContainer: RootContainerViewController?
#if targetEnvironment(simulator)
let simulatorTunnelProvider = SimulatorTunnelProviderHost()
@@ -50,6 +51,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
let rootViewController = RootContainerViewController()
+ rootViewController.delegate = self
let showMainController = { (_ animated: Bool) in
self.showMainController(in: rootViewController, animated: animated) {
@@ -68,6 +70,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
self.window?.rootViewController = rootViewController
+ self.rootContainer = rootViewController
}
}
@@ -114,6 +117,39 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
+extension AppDelegate: RootContainerViewControllerDelegate {
+
+ func rootContainerViewControllerShouldShowSettings(_ controller: RootContainerViewController, navigateTo route: SettingsNavigationRoute?, animated: Bool) {
+ guard let navController = mainStoryboard
+ .instantiateViewController(withIdentifier: ViewControllerIdentifier.settings.rawValue)
+ as? UINavigationController else { return }
+
+ guard let settingsController = navController.topViewController as? SettingsViewController else { return }
+ settingsController.settingsDelegate = self
+
+ if let route = route {
+ settingsController.navigate(to: route)
+ }
+
+ controller.present(navController, animated: animated)
+ }
+}
+
+extension AppDelegate: SettingsViewControllerDelegate {
+
+ func settingsViewController(_ controller: SettingsViewController, didFinishWithReason reason: SettingsDismissReason) {
+ if case .userLoggedOut = reason {
+ rootContainer?.popToRootViewController(animated: false)
+
+ let loginController = rootContainer?.topViewController as? LoginViewController
+
+ loginController?.reset()
+ }
+ controller.dismiss(animated: true)
+ }
+
+}
+
extension AppDelegate: AppStorePaymentManagerDelegate {
func appStorePaymentManager(_ manager: AppStorePaymentManager,
diff --git a/ios/MullvadVPN/LoginViewController.swift b/ios/MullvadVPN/LoginViewController.swift
index 9138e15bbb..1ee718b534 100644
--- a/ios/MullvadVPN/LoginViewController.swift
+++ b/ios/MullvadVPN/LoginViewController.swift
@@ -99,6 +99,14 @@ class LoginViewController: UIViewController, RootContainment {
object: accountTextField)
}
+ // MARK: - Public
+
+ func reset() {
+ loginState = .default
+ accountTextField.autoformattingText = ""
+ updateKeyboardToolbar()
+ }
+
// MARK: - Keyboard notifications
@objc private func keyboardWillShow(_ notification: Notification) {
@@ -140,12 +148,6 @@ class LoginViewController: UIViewController, RootContainment {
// MARK: - Actions
- @IBAction func unwindFromAccount(segue: UIStoryboardSegue) {
- loginState = .default
- accountTextField.autoformattingText = ""
- updateKeyboardToolbar()
- }
-
@IBAction func cancelLogin() {
view.endEditing(true)
}
diff --git a/ios/MullvadVPN/RootContainerViewController.swift b/ios/MullvadVPN/RootContainerViewController.swift
index 20013017e8..7eed0459bc 100644
--- a/ios/MullvadVPN/RootContainerViewController.swift
+++ b/ios/MullvadVPN/RootContainerViewController.swift
@@ -36,23 +36,29 @@ protocol RootContainment {
}
+protocol RootContainerViewControllerDelegate: class {
+ func rootContainerViewControllerShouldShowSettings(_ controller: RootContainerViewController, navigateTo route: SettingsNavigationRoute?, animated: Bool)
+}
+
/// A root container class that primarily handles the unwind storyboard segues on log out
class RootContainerViewController: UIViewController {
typealias CompletionHandler = () -> Void
- private var viewControllers = [UIViewController]()
-
- private var topViewController: UIViewController? {
- return viewControllers.last
- }
-
private let headerBarView = HeaderBarView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
private let transitionContainer = UIView(frame: UIScreen.main.bounds)
private(set) var headerBarStyle = HeaderBarStyle.default
private(set) var headerBarHidden = false
+ private(set) var viewControllers = [UIViewController]()
+
+ var topViewController: UIViewController? {
+ return viewControllers.last
+ }
+
+ weak var delegate: RootContainerViewControllerDelegate?
+
override var childForStatusBarStyle: UIViewController? {
return topViewController
}
@@ -164,18 +170,7 @@ class RootContainerViewController: UIViewController {
/// Request to display settings controller
func showSettings(navigateTo route: SettingsNavigationRoute? = nil, animated: Bool) {
- let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
-
- guard let navController = mainStoryboard
- .instantiateViewController(withIdentifier: ViewControllerIdentifier.settings.rawValue)
- as? UINavigationController else { return }
-
- if let route = route {
- let settingsController = navController.topViewController as? SettingsViewController
- settingsController?.navigate(to: route)
- }
-
- present(navController, animated: animated)
+ delegate?.rootContainerViewControllerShouldShowSettings(self, navigateTo: route, animated: animated)
}
/// Enable or disable the settings bar button displayed in the header bar
diff --git a/ios/MullvadVPN/SettingsViewController.swift b/ios/MullvadVPN/SettingsViewController.swift
index 721c9c42ae..a3b3ab3f8a 100644
--- a/ios/MullvadVPN/SettingsViewController.swift
+++ b/ios/MullvadVPN/SettingsViewController.swift
@@ -14,7 +14,16 @@ enum SettingsNavigationRoute {
case wireguardKeys
}
-class SettingsViewController: UITableViewController {
+enum SettingsDismissReason {
+ case none
+ case userLoggedOut
+}
+
+protocol SettingsViewControllerDelegate: class {
+ func settingsViewController(_ controller: SettingsViewController, didFinishWithReason reason: SettingsDismissReason)
+}
+
+class SettingsViewController: UITableViewController, AccountViewControllerDelegate {
@IBOutlet var staticDataSource: SettingsTableViewDataSource!
@@ -28,6 +37,8 @@ class SettingsViewController: UITableViewController {
private weak var accountRow: StaticTableViewRow?
private var accountExpiryObserver: NSObjectProtocol?
+ weak var settingsDelegate: SettingsViewControllerDelegate?
+
override func viewDidLoad() {
super.viewDidLoad()
@@ -46,7 +57,7 @@ class SettingsViewController: UITableViewController {
// MARK: - IBActions
@IBAction func handleDismiss() {
- dismiss(animated: true)
+ settingsDelegate?.settingsViewController(self, didFinishWithReason: .none)
}
// MARK: - Navigation
@@ -55,11 +66,7 @@ class SettingsViewController: UITableViewController {
switch route {
case .account:
let controller = AccountViewController()
- controller.didFinishLogout = { [weak self] in
- self?.dismiss(animated: true) {
- // TODO: pop to login controller
- }
- }
+ controller.delegate = self
navigationController?.pushViewController(controller, animated: true)
@@ -70,6 +77,12 @@ class SettingsViewController: UITableViewController {
}
}
+ // MARK: - AccountViewControllerDelegate
+
+ func accountViewControllerDidLogout(_ controller: AccountViewController) {
+ settingsDelegate?.settingsViewController(self, didFinishWithReason: .userLoggedOut)
+ }
+
// MARK: - Private
private func setupDataSource() {