Commit 40885878 authored by Carola Nitz's avatar Carola Nitz

Introduce Coordinator pattern

parent 75fd8a64
//
// AppCoordinator.swift
// VLC-iOS
//
// Created by Carola Nitz on 11/30/17.
// Copyright © 2017 VideoLAN. All rights reserved.
//
import Foundation
@objc class AppCoordinator : NSObject, Coordinator {
let services: Services
var childCoordinators: [Coordinator] = []
var rootViewController: UIViewController {
return self.navigationController
}
/// Window to manage
let window: UIWindow
private lazy var navigationController: UINavigationController = {
let navigationController = UINavigationController()
navigationController.isNavigationBarHidden = true
return navigationController
}()
@objc public init(window: UIWindow) {
self.services = Services()
self.window = window
super.init()
self.window.rootViewController = self.rootViewController
self.window.makeKeyAndVisible()
}
@objc public func start() {
showPlayerDisplayController()
}
private func showPlayerDisplayController() {
if let playerDisplayController = VLCPlayerDisplayController.sharedInstance() {
navigationController.setViewControllers([playerDisplayController], animated: true)
}
}
}
//
// Coordinator.swift
// VLC-iOS
//
// Created by Carola Nitz on 12/1/17.
// Copyright © 2017 VideoLAN. All rights reserved.
//
import Foundation
struct Services {
}
/// The Coordinator protocol
protocol Coordinator: class {
/// The services that the coordinator can use
var services: Services { get }
/// The array containing any child Coordinators
var childCoordinators: [Coordinator] { get set }
}
extension Coordinator {
/// Add a child coordinator to the parent
func addChildCoordinator(childCoordinator: Coordinator) {
self.childCoordinators.append(childCoordinator)
}
/// Remove a child coordinator from the parent
func removeChildCoordinator(childCoordinator: Coordinator) {
self.childCoordinators = self.childCoordinators.filter { $0 !== childCoordinator }
}
}
......@@ -35,7 +35,6 @@ struct DropError: Error {
@available(iOS 11.0, *)
class VLCDragAndDropManager: NSObject, UICollectionViewDragDelegate, UITableViewDragDelegate, UICollectionViewDropDelegate, UITableViewDropDelegate, UIDropInteractionDelegate
{
@objc weak var delegate:VLCDragAndDropManagerDelegate?
let utiTypeIdentifiers:[String] = VLCDragAndDropManager.supportedTypeIdentifiers()
......
......@@ -30,7 +30,6 @@
#import "VLCPlayerDisplayController.h"
#import <MediaPlayer/MediaPlayer.h>
#import <HockeySDK/HockeySDK.h>
#import "VLCSidebarController.h"
#import "VLCActivityManager.h"
#import "VLCDropboxConstants.h"
#import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
......@@ -48,6 +47,7 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
BOOL _isComingFromHandoff;
VLCWatchCommunication *_watchCommunication;
VLCKeychainCoordinator *_keychainCoordinator;
AppCoordinator *appCoordinator;
}
@end
......@@ -111,16 +111,10 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
void (^setupBlock)() = ^{
__weak typeof(self) weakSelf = self;
void (^setupLibraryBlock)() = ^{
_libraryViewController = [[VLCLibraryViewController alloc] init];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_libraryViewController];
VLCSidebarController *sidebarVC = [VLCSidebarController sharedInstance];
sidebarVC.contentViewController = navCon;
VLCPlayerDisplayController *playerDisplayController = [VLCPlayerDisplayController sharedInstance];
playerDisplayController.childViewController = sidebarVC.fullViewController;
weakSelf.window.rootViewController = playerDisplayController;
_libraryViewController = [[VLCLibraryViewController alloc] init];
appCoordinator = [[AppCoordinator alloc] initWithWindow:weakSelf.window];
[appCoordinator start];
};
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]];
self.window.rootViewController = navCon;
......
......@@ -28,8 +28,6 @@ typedef NS_ENUM(NSUInteger, VLCPlayerDisplayControllerDisplayMode) {
+ (VLCPlayerDisplayController *)sharedInstance;
@property (nonatomic, strong) UIViewController *childViewController;
@property (nonatomic, assign) VLCPlayerDisplayControllerDisplayMode displayMode;
@property (nonatomic, weak) VLCPlaybackController *playbackController;
......
......@@ -14,6 +14,8 @@
#import "VLCPlaybackController.h"
#import "VLCMiniPlaybackView.h"
#import "VLCPlaybackNavigationController.h"
#import "VLCAppDelegate.h"
#import "VLC_iOS-Swift.h"
#if TARGET_OS_IOS
#import "VLCMovieViewController.h"
......@@ -26,6 +28,7 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
@interface VLCPlayerDisplayController ()
@property (nonatomic, strong) UIViewController<VLCPlaybackControllerDelegate> *movieViewController;
@property (nonatomic, strong) UIView<VLCPlaybackControllerDelegate, VLCMiniPlaybackViewInterface> *miniPlaybackView;
@property (nonatomic, strong) UIViewController *childViewController;
@end
@implementation VLCPlayerDisplayController
......@@ -67,6 +70,14 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
- (void)viewDidLoad
{
[super viewDidLoad];
VLCSidebarController *sidebarVC = [VLCSidebarController sharedInstance];
VLCLibraryViewController *libCon = ((VLCAppDelegate *)[UIApplication sharedApplication].delegate).libraryViewController;
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:libCon];
sidebarVC.contentViewController = navCon;
_childViewController = sidebarVC.fullViewController;
[self setupChildViewController];
}
......
......@@ -4,8 +4,11 @@
#import <MediaLibraryKit/MediaLibraryKit.h>
#import "VLCPlaylistTableViewCell.h"
#import "VLCPlaylistCollectionViewCell.h"
#import "VLCMediaDataSource.h"
#import "VLCLibraryViewController.h"
#import <PAPasscode/PAPasscodeViewController.h>
#import <XKKeychain/XKKeychain.h>
#import "VLCConstants.h"
#import "UIBarButtonItem+Theme.h"
#import "VLCSidebarController.h"
#import "VLCPlayerDisplayController.h"
......@@ -17,6 +17,8 @@
26F1BFD01A770408001DF30C /* libMediaVLC.xml in Resources */ = {isa = PBXBuildFile; fileRef = 26F1BFCF1A770408001DF30C /* libMediaVLC.xml */; };
29125E5617492219003F03E5 /* index.html in Resources */ = {isa = PBXBuildFile; fileRef = 29125E5417492219003F03E5 /* index.html */; };
2915544317490D4A00B86CAD /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2915544217490D4A00B86CAD /* Security.framework */; };
41251ED01FD0CF7900099110 /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41251ECE1FD0CF7900099110 /* AppCoordinator.swift */; };
41251ED11FD0CF7900099110 /* Coordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41251ECF1FD0CF7900099110 /* Coordinator.swift */; };
41273A3C1A955C4100A2EF77 /* VLCMigrationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */; };
41273A3D1A955C4100A2EF77 /* VLCMigrationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */; };
412BE7531FC4947400ACCC42 /* VLCMediaData+VLCDragAndDrop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 412BE7521FC4947400ACCC42 /* VLCMediaData+VLCDragAndDrop.swift */; };
......@@ -735,6 +737,9 @@
3C12F87F27BDCE3D0A58354E /* Pods-VLC-iOS-no-watch-Debug.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VLC-iOS-no-watch-Debug.debug.xcconfig"; path = "Pods/Target Support Files/Pods-VLC-iOS-no-watch-Debug/Pods-VLC-iOS-no-watch-Debug.debug.xcconfig"; sourceTree = "<group>"; };
3DD533B1D45EEA70099433D8 /* libPods-VLC-iOS-no-watch.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VLC-iOS-no-watch.a"; sourceTree = BUILT_PRODUCTS_DIR; };
402E6F0E5362B530B7909338 /* libPods-VLC-iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VLC-iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
41251ECB1FD0C5C100099110 /* VLC-iOS-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "VLC-iOS-Bridging-Header.h"; sourceTree = SOURCE_ROOT; };
41251ECE1FD0CF7900099110 /* AppCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppCoordinator.swift; path = SharedSources/Coordinators/AppCoordinator.swift; sourceTree = SOURCE_ROOT; };
41251ECF1FD0CF7900099110 /* Coordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Coordinator.swift; path = SharedSources/Coordinators/Coordinator.swift; sourceTree = SOURCE_ROOT; };
41273A391A955C4100A2EF77 /* VLCMigrationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCMigrationViewController.h; path = Sources/VLCMigrationViewController.h; sourceTree = SOURCE_ROOT; };
41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCMigrationViewController.m; path = Sources/VLCMigrationViewController.m; sourceTree = SOURCE_ROOT; };
41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VLCMigrationViewController.xib; path = Sources/VLCMigrationViewController.xib; sourceTree = SOURCE_ROOT; };
......@@ -809,7 +814,6 @@
41B93C031A53835300102E8B /* VLCCloudServiceCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCCloudServiceCell.m; path = Sources/VLCCloudServiceCell.m; sourceTree = SOURCE_ROOT; };
41B93C071A53853B00102E8B /* VLCCloudServiceCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VLCCloudServiceCell.xib; path = Resources/VLCCloudServiceCell.xib; sourceTree = SOURCE_ROOT; };
41BBDCBC1F3BAD2E00B89A9C /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
41BBF90E1FC31A8E003A72CB /* VLC-iOS-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "VLC-iOS-Bridging-Header.h"; sourceTree = "<group>"; };
41BBF90F1FC31A8E003A72CB /* VLCDragAndDropManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = VLCDragAndDropManager.swift; path = SharedSources/VLCDragAndDropManager.swift; sourceTree = SOURCE_ROOT; };
41CD69571A29D72600E60BCE /* VLCBoxConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCBoxConstants.h; path = Sources/VLCBoxConstants.h; sourceTree = SOURCE_ROOT; };
41CD69581A29D72600E60BCE /* VLCBoxController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCBoxController.h; path = Sources/VLCBoxController.h; sourceTree = SOURCE_ROOT; };
......@@ -1589,6 +1593,15 @@
name = "Recovered References";
sourceTree = "<group>";
};
415163B01FD0AEC700161354 /* Coordinators */ = {
isa = PBXGroup;
children = (
41251ECE1FD0CF7900099110 /* AppCoordinator.swift */,
41251ECF1FD0CF7900099110 /* Coordinator.swift */,
);
path = Coordinators;
sourceTree = "<group>";
};
41B0BC871F73ED7D0063BA26 /* VLC for iOSUITests */ = {
isa = PBXGroup;
children = (
......@@ -1864,6 +1877,7 @@
7D5F7AB81752658E006CCCFA /* Everything Playlist */ = {
isa = PBXGroup;
children = (
41251ECB1FD0C5C100099110 /* VLC-iOS-Bridging-Header.h */,
4171D34E18A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.h */,
4171D34F18A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.m */,
7D378493183A98D1009EE944 /* VLCPlaylistCollectionViewCell.h */,
......@@ -1879,7 +1893,6 @@
41F5C0791F42E567005EB9CB /* VLCMediaDataSource.h */,
41F5C07A1F42E567005EB9CB /* VLCMediaDataSource.m */,
41BBF90F1FC31A8E003A72CB /* VLCDragAndDropManager.swift */,
41BBF90E1FC31A8E003A72CB /* VLC-iOS-Bridging-Header.h */,
412BE7521FC4947400ACCC42 /* VLCMediaData+VLCDragAndDrop.swift */,
);
name = "Everything Playlist";
......@@ -2075,6 +2088,7 @@
7D94FCE416DE7D1000F2623B /* iOS specific classes */ = {
isa = PBXGroup;
children = (
415163B01FD0AEC700161354 /* Coordinators */,
41273A391A955C4100A2EF77 /* VLCMigrationViewController.h */,
41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */,
7D6B08BB174A72A900A05173 /* VLCConstants.h */,
......@@ -3737,6 +3751,7 @@
files = (
4144C4661A0ED6C700918C89 /* Reachability.m in Sources */,
DD846BDF1D1FCCCD00699D17 /* VLCNetworkLoginDataSource.m in Sources */,
41251ED01FD0CF7900099110 /* AppCoordinator.swift in Sources */,
4184AA151A5492070063DF5A /* VLCCloudStorageController.m in Sources */,
9BE4D1CE183D76950006346C /* VLCCloudStorageTableViewCell.m in Sources */,
41F5C07B1F42E567005EB9CB /* VLCMediaDataSource.m in Sources */,
......@@ -3851,6 +3866,7 @@
7D1052EE1A4DCD1E00295F08 /* VLCOneDriveController.m in Sources */,
7DAE0C371B2EF85B00C53996 /* VLCSidebarController.m in Sources */,
7D30F3DC183AB2F900FFC021 /* VLCNetworkLoginViewController.m in Sources */,
41251ED11FD0CF7900099110 /* Coordinator.swift in Sources */,
419A2C661F37A4B70069D224 /* VLCStringsForLocalization.m in Sources */,
DDA1B9091CE902EE0076BC45 /* VLCNetworkServerLoginInformation+Keychain.m in Sources */,
7D30F3DF183AB31E00FFC021 /* VLCWiFiUploadTableViewCell.m in Sources */,
......@@ -4481,7 +4497,6 @@
OTHER_LDFLAGS = "-ObjC";
PRODUCT_MODULE_NAME = VLC_iOS;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALID_ARCHS = "arm64 armv7 armv7s";
......@@ -4560,6 +4575,7 @@
PROVISIONING_PROFILE = "";
SKIP_INSTALL = NO;
SWIFT_OBJC_BRIDGING_HEADER = "VLC-iOS-Bridging-Header.h";
SWIFT_VERSION = 4.0;
VALID_ARCHS = "arm64 armv7 armv7s";
};
name = Debug;
......@@ -4604,6 +4620,7 @@
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SKIP_INSTALL = NO;
SWIFT_OBJC_BRIDGING_HEADER = "VLC-iOS-Bridging-Header.h";
SWIFT_VERSION = 4.0;
VALID_ARCHS = "arm64 armv7 armv7s";
};
name = Release;
......@@ -4814,6 +4831,7 @@
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SKIP_INSTALL = NO;
SWIFT_OBJC_BRIDGING_HEADER = "VLC-iOS-Bridging-Header.h";
SWIFT_VERSION = 4.0;
VALID_ARCHS = "arm64 armv7 armv7s";
};
name = Distribution;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment