Move profile reactions to delegate

- Activation
- Removal
This commit is contained in:
Davide De Rosa 2018-11-03 23:40:07 +01:00
parent e22cce510c
commit 8e445e90b3
3 changed files with 16 additions and 10 deletions

View File

@ -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()
}
}

View File

@ -186,7 +186,6 @@ class ServiceViewController: UIViewController, TableModelHost {
private func activateProfile() {
service.activateProfile(uncheckedProfile)
TransientStore.shared.serialize() // activate
reloadModel()
tableView.reloadData()

View File

@ -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)
}