diff --git a/WireGuard/ViewControllers/ProfileConfigurationTableViewController.swift b/WireGuard/ViewControllers/ProfileConfigurationTableViewController.swift new file mode 100644 index 0000000..39290d4 --- /dev/null +++ b/WireGuard/ViewControllers/ProfileConfigurationTableViewController.swift @@ -0,0 +1,51 @@ +// +// ProfileConfigurationTableViewController.swift +// WireGuard +// +// Created by Jeroen Leenarts on 24-05-18. +// Copyright © 2018 Wireguard. All rights reserved. +// + +import UIKit +import CoreData +import BNRCoreDataStack + +protocol ProfileConfigurationTableViewControllerDelegate: class { +} + +class ProfileConfigurationTableViewController: UITableViewController { + var viewContext: NSManagedObjectContext! + weak var delegate: ProfileConfigurationTableViewControllerDelegate? + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 3 + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + switch indexPath.row { + case 0: + return tableView.dequeueReusableCell(type: InterfaceTableViewCell.self, for: indexPath) + case 1: + return tableView.dequeueReusableCell(type: PeerTableViewCell.self, for: indexPath) + default: + return tableView.dequeueReusableCell(type: AddPeerTableViewCell.self, for: indexPath) + } + } +} + +class InterfaceTableViewCell: UITableViewCell { + +} + +class PeerTableViewCell: UITableViewCell { + +} + +class AddPeerTableViewCell: UITableViewCell { + +} + +extension ProfileConfigurationTableViewController: Identifyable {} +extension InterfaceTableViewCell: Identifyable {} +extension PeerTableViewCell: Identifyable {} +extension AddPeerTableViewCell: Identifyable {} diff --git a/Wireguard.xcodeproj/project.pbxproj b/Wireguard.xcodeproj/project.pbxproj index 90ec6e3..6b0a645 100644 --- a/Wireguard.xcodeproj/project.pbxproj +++ b/Wireguard.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 48CF751B34E9703133F1B1AF /* Pods_WireGuard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 861983CAE8FDC13BC83E7E04 /* Pods_WireGuard.framework */; }; + 4A4BA6D820B73CBA00223AB8 /* ProfileConfigurationTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A4BA6D720B73CBA00223AB8 /* ProfileConfigurationTableViewController.swift */; }; 4A4BACE620B5F1BF00F12B28 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A4BACE520B5F1BF00F12B28 /* AppDelegate.swift */; }; 4A4BACE820B5F1BF00F12B28 /* ConnectionsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A4BACE720B5F1BF00F12B28 /* ConnectionsTableViewController.swift */; }; 4A4BACEB20B5F1BF00F12B28 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A4BACE920B5F1BF00F12B28 /* Main.storyboard */; }; @@ -44,6 +45,7 @@ /* Begin PBXFileReference section */ 0CE52E030FAA93F3BF5747B2 /* Pods-WireGuard.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WireGuard.release.xcconfig"; path = "Pods/Target Support Files/Pods-WireGuard/Pods-WireGuard.release.xcconfig"; sourceTree = ""; }; 25E2BE31A33C8CCE6E79B6EF /* Pods-WireGuard.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WireGuard.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WireGuard/Pods-WireGuard.debug.xcconfig"; sourceTree = ""; }; + 4A4BA6D720B73CBA00223AB8 /* ProfileConfigurationTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileConfigurationTableViewController.swift; sourceTree = ""; }; 4A4BACE220B5F1BF00F12B28 /* WireGuard.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WireGuard.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4A4BACE520B5F1BF00F12B28 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 4A4BACE720B5F1BF00F12B28 /* ConnectionsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionsTableViewController.swift; sourceTree = ""; }; @@ -161,8 +163,9 @@ isa = PBXGroup; children = ( 4A4BAD1220B5F82400F12B28 /* Identifyable.swift */, - 4A4BACE720B5F1BF00F12B28 /* ConnectionsTableViewController.swift */, 4A8AABD720B6A79100B6D8C1 /* UITableView+WireGuard.swift */, + 4A4BACE720B5F1BF00F12B28 /* ConnectionsTableViewController.swift */, + 4A4BA6D720B73CBA00223AB8 /* ProfileConfigurationTableViewController.swift */, ); path = ViewControllers; sourceTree = ""; @@ -401,6 +404,7 @@ 4A4BACE820B5F1BF00F12B28 /* ConnectionsTableViewController.swift in Sources */, 4A4BAD1020B5F6EC00F12B28 /* RootCoordinator.swift in Sources */, 4A4BAD0E20B5F6C300F12B28 /* Coordinator.swift in Sources */, + 4A4BA6D820B73CBA00223AB8 /* ProfileConfigurationTableViewController.swift in Sources */, 4A4BAD2020B6026900F12B28 /* Peer+CoreDataProperties.swift in Sources */, 4A4BAD2320B6026900F12B28 /* Interface+CoreDataClass.swift in Sources */, 4A7F6EDD20B674CD00B260B7 /* Address+CoreDataClass.swift in Sources */, diff --git a/Wireguard/Base.lproj/Main.storyboard b/Wireguard/Base.lproj/Main.storyboard index f1dff1e..b7bad2e 100644 --- a/Wireguard/Base.lproj/Main.storyboard +++ b/Wireguard/Base.lproj/Main.storyboard @@ -6,6 +6,8 @@ + + @@ -54,5 +56,351 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wireguard/Coordinators/AppCoordinator.swift b/Wireguard/Coordinators/AppCoordinator.swift index b03807f..477911d 100644 --- a/Wireguard/Coordinators/AppCoordinator.swift +++ b/Wireguard/Coordinators/AppCoordinator.swift @@ -85,8 +85,8 @@ class AppCoordinator: RootViewCoordinator { extension AppCoordinator: ConnectionsTableViewControllerDelegate { func addProvider(connectionsTableViewController: ConnectionsTableViewController) { - // TODO implement - print("Add provider") + let addContext = persistentContainer.newBackgroundContext() + showProfileConfigurationViewController(profile: nil, context: addContext) } func connect(profile: Profile, connectionsTableViewController: ConnectionsTableViewController) { @@ -97,6 +97,23 @@ extension AppCoordinator: ConnectionsTableViewControllerDelegate { func configure(profile: Profile, connectionsTableViewController: ConnectionsTableViewController) { // TODO implement print("configure profile \(profile)") + let editContext = persistentContainer.newBackgroundContext() + var backgroundProfile: Profile? + editContext.performAndWait { + + backgroundProfile = editContext.object(with: profile.objectID) as? Profile + } + + showProfileConfigurationViewController(profile: backgroundProfile, context: editContext) + } + + func showProfileConfigurationViewController(profile: Profile?, context: NSManagedObjectContext) { + let profileConfigurationViewController = storyboard.instantiateViewController(type: ProfileConfigurationTableViewController.self) + + profileConfigurationViewController.viewContext = context + profileConfigurationViewController.delegate = self + + self.navigationController.pushViewController(profileConfigurationViewController, animated: true) } func delete(profile: Profile, connectionsTableViewController: ConnectionsTableViewController) { @@ -104,3 +121,7 @@ extension AppCoordinator: ConnectionsTableViewControllerDelegate { print("delete profile \(profile)") } } + +extension AppCoordinator: ProfileConfigurationTableViewControllerDelegate { + +}