From 8e445e90b3c2cf240964f5f7cba78e16e2eb4b47 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 3 Nov 2018 23:40:07 +0100 Subject: [PATCH] Move profile reactions to delegate - Activation - Removal --- .../Organizer/OrganizerViewController.swift | 15 +++++++++++---- .../Scenes/ServiceViewController.swift | 1 - .../Sources/Model/ConnectionService.swift | 10 +++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift b/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift index bebb2427..0604d80c 100644 --- a/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift @@ -217,9 +217,7 @@ class OrganizerViewController: UITableViewController, TableModelHost { // } tableView.endUpdates() - let _ = service.removeProfile(rowProfile) - splitViewController?.serviceViewController?.hideProfileIfDeleted() - TransientStore.shared.serialize() // delete + service.removeProfile(rowProfile) } private func confirmVpnProfileDeletion() { @@ -453,15 +451,24 @@ extension OrganizerViewController: ConnectionServiceDelegate { } func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey) { + splitViewController?.serviceViewController?.hideProfileIfDeleted() + TransientStore.shared.serialize() // delete + reloadModel() tableView.reloadData() } - func connectionService(didDeactivate profile: ConnectionProfile) { + // XXX: deactivate + activate leads to a redundant serialization + + func connectionService(willDeactivate profile: ConnectionProfile) { + TransientStore.shared.serialize() // deactivate + tableView.reloadData() } func connectionService(didActivate profile: ConnectionProfile) { + TransientStore.shared.serialize() // activate + tableView.reloadData() } } diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index 488e0f6f..79fc17ac 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -186,7 +186,6 @@ class ServiceViewController: UIViewController, TableModelHost { private func activateProfile() { service.activateProfile(uncheckedProfile) - TransientStore.shared.serialize() // activate reloadModel() tableView.reloadData() diff --git a/Passepartout/Sources/Model/ConnectionService.swift b/Passepartout/Sources/Model/ConnectionService.swift index 9e9b5bc8..7911fcd9 100644 --- a/Passepartout/Sources/Model/ConnectionService.swift +++ b/Passepartout/Sources/Model/ConnectionService.swift @@ -37,9 +37,9 @@ protocol ConnectionServiceDelegate: class { func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey) - func connectionService(didActivate profile: ConnectionProfile) + func connectionService(willDeactivate profile: ConnectionProfile) - func connectionService(didDeactivate profile: ConnectionProfile) + func connectionService(didActivate profile: ConnectionProfile) } class ConnectionService: Codable { @@ -120,7 +120,7 @@ class ConnectionService: Codable { private(set) var activeProfileKey: ProfileKey? { willSet { if let oldProfile = activeProfile { - delegate?.connectionService(didDeactivate: oldProfile) + delegate?.connectionService(willDeactivate: oldProfile) } } didSet { @@ -348,7 +348,7 @@ class ConnectionService: Codable { delegate?.connectionService(didAdd: profile) } - func renameProfile(_ key: ProfileKey, to newId: String) -> ConnectionProfile? { + @discardableResult func renameProfile(_ key: ProfileKey, to newId: String) -> ConnectionProfile? { precondition(newId != key.id) // WARNING: can be a placeholder @@ -390,7 +390,7 @@ class ConnectionService: Codable { return newProfile } - func renameProfile(_ profile: ConnectionProfile, to id: String) -> ConnectionProfile? { + @discardableResult func renameProfile(_ profile: ConnectionProfile, to id: String) -> ConnectionProfile? { return renameProfile(ProfileKey(profile), to: id) }