From 1d7cdc7f199b717969d8133422aa69da3e59ead8 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 27 Oct 2019 21:56:06 +0100 Subject: [PATCH] Move trust actions to separate functions --- .../Scenes/ServiceViewController.swift | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index b5a550ff..2f1d95e5 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -346,6 +346,15 @@ class ServiceViewController: UIViewController, StrongTableHost { } } + private func trustMobileNetwork(cell: ToggleTableViewCell) { + if #available(iOS 12, *) { + IntentDispatcher.donateTrustCellularNetwork() + IntentDispatcher.donateUntrustCellularNetwork() + } + + trustedNetworks.setMobile(cell.isOn) + } + private func trustCurrentWiFi() { if #available(iOS 13, *) { let auth = CLLocationManager.authorizationStatus() @@ -390,6 +399,14 @@ class ServiceViewController: UIViewController, StrongTableHost { } } + private func toggleTrustWiFi(cell: ToggleTableViewCell, at row: Int) { + if cell.isOn { + trustedNetworks.enableWifi(at: row) + } else { + trustedNetworks.disableWifi(at: row) + } + } + private func toggleTrustedConnectionPolicy(_ isOn: Bool, sender: ToggleTableViewCell) { let completionHandler: () -> Void = { self.service.preferences.trustPolicy = isOn ? .disconnect : .ignore @@ -1071,22 +1088,13 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog toggleDisconnectsOnSleep(cell.isOn) case .trustedMobile: - if #available(iOS 12, *) { - IntentDispatcher.donateTrustCellularNetwork() - IntentDispatcher.donateUntrustCellularNetwork() - } - - trustedNetworks.setMobile(cell.isOn) + trustMobileNetwork(cell: cell) case .trustedWiFi: guard let indexPath = tableView.indexPath(for: cell) else { return } - if cell.isOn { - trustedNetworks.enableWifi(at: indexPath.row) - } else { - trustedNetworks.disableWifi(at: indexPath.row) - } + toggleTrustWiFi(cell: cell, at: indexPath.row) case .trustedPolicy: toggleTrustedConnectionPolicy(cell.isOn, sender: cell)