瀏覽代碼

VLCTabBarCoordinator: Move unrelated logic

Soomin Lee 7 年之前
父節點
當前提交
8dac4cbabe
共有 3 個文件被更改,包括 40 次插入45 次删除
  1. 12 5
      Sources/Coordinators/AppCoordinator.swift
  2. 22 10
      Sources/MediaViewController.swift
  3. 6 30
      Sources/VLCTabBarCoordinator.swift

+ 12 - 5
Sources/Coordinators/AppCoordinator.swift

@@ -9,7 +9,6 @@
  *
  * Refer to the COPYING file of the official project for license.
  *****************************************************************************/
-import Foundation
 
 @objc(VLCService)
 class Services: NSObject {
@@ -18,19 +17,27 @@ class Services: NSObject {
 }
 
 @objc class AppCoordinator: NSObject {
-
-    var childCoordinators: [NSObject] = []
+    private var childCoordinators: [NSObject] = []
     private var tabBarController: UITabBarController
+    private var playerController: VLCPlayerDisplayController
     private var services = Services()
 
     @objc init(tabBarController: UITabBarController) {
         self.tabBarController = tabBarController
+        self.playerController = VLCPlayerDisplayController(services: services)
         super.init()
+        setupPlayerController()
+    }
+
+    private func setupPlayerController() {
+        tabBarController.addChildViewController(playerController)
+        tabBarController.view.addSubview(playerController.view)
+        playerController.view.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: tabBarController.tabBar.frame.size.height, right: 0)
+        playerController.didMove(toParentViewController: tabBarController)
     }
 
     @objc func start() {
-        let tabbarCoordinator = VLCTabbarCooordinator(tabBarController: tabBarController, services: services)
-        tabbarCoordinator.start()
+        let tabbarCoordinator = VLCTabBarCoordinator(tabBarController: tabBarController, services: services)
         childCoordinators.append(tabbarCoordinator)
     }
 }

+ 22 - 10
Sources/MediaViewController.swift

@@ -15,11 +15,11 @@ import UIKit
 class VLCVideoViewController: VLCMediaViewController {
     override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
         let movies = VLCMediaCategoryViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.movies)
-        movies.delegate = mediaDelegate
+        movies.delegate = super.self()
         let episodes = VLCMediaCategoryViewController<MLShowEpisode>(services: services, subcategory: VLCMediaSubcategories.episodes)
-        episodes.delegate = mediaDelegate
+        episodes.delegate = super.self()
         let playlists = VLCMediaCategoryViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.videoPlaylists)
-        playlists.delegate = mediaDelegate
+        playlists.delegate = super.self()
         return [movies, episodes, playlists]
     }
 }
@@ -27,23 +27,21 @@ class VLCVideoViewController: VLCMediaViewController {
 class VLCAudioViewController: VLCMediaViewController {
     override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
         let tracks = VLCMediaCategoryViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.tracks)
-        tracks.delegate = mediaDelegate
+        tracks.delegate = super.self()
         let genres = VLCMediaCategoryViewController<String>(services: services, subcategory: VLCMediaSubcategories.genres)
-        genres.delegate = mediaDelegate
+        genres.delegate = super.self()
         let artists = VLCMediaCategoryViewController<String>(services: services, subcategory: VLCMediaSubcategories.artists)
-        artists.delegate = mediaDelegate
+        artists.delegate = super.self()
         let albums = VLCMediaCategoryViewController<MLAlbum>(services: services, subcategory: VLCMediaSubcategories.albums)
-        albums.delegate = mediaDelegate
+        albums.delegate = super.self()
         let playlists = VLCMediaCategoryViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.audioPlaylists)
-        playlists.delegate = mediaDelegate
+        playlists.delegate = super.self()
         return [tracks, genres, artists, albums, playlists]
     }
 }
 
 class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
-
     var services: Services
-    weak var mediaDelegate: VLCMediaCategoryViewControllerDelegate?
     private var rendererButton: UIButton
 
     init(services: Services) {
@@ -107,3 +105,17 @@ class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
         return PresentationTheme.current.colors.statusBarStyle
     }
 }
+
+// MARK: - VLCMediaCategoryViewControllerDelegate
+extension VLCMediaViewController: VLCMediaCategoryViewControllerDelegate {
+
+    func mediaViewControllerDidSelectMediaObject(_ viewcontroller: UIViewController, mediaObject: NSManagedObject) {
+        playMedia(media: mediaObject)
+    }
+
+    func playMedia(media: NSManagedObject) {
+        //that should go into a Coordinator itself
+        let vpc = VLCPlaybackController.sharedInstance()
+        vpc?.playMediaLibraryObject(media)
+    }
+}

+ 6 - 30
Sources/VLCTabBarCoordinator.swift

@@ -1,5 +1,5 @@
 /*****************************************************************************
- * VLCTabbarCooordinator.swift
+ * VLCTabBarCoordinator.swift
  * VLC for iOS
  *****************************************************************************
  * Copyright (c) 2018 VideoLAN. All rights reserved.
@@ -10,24 +10,19 @@
  * Refer to the COPYING file of the official project for license.
  *****************************************************************************/
 
-import Foundation
-
-class VLCTabbarCooordinator: NSObject, VLCMediaCategoryViewControllerDelegate {
-
-    private var childCoordinators: [NSObject] = []
+class VLCTabBarCoordinator: NSObject {
     private var tabBarController: UITabBarController
     private var services: Services
-    private var displayController: VLCPlayerDisplayController
 
     init(tabBarController: UITabBarController, services: Services) {
         self.tabBarController = tabBarController
         self.services = services
-        displayController = VLCPlayerDisplayController(services: services)
         super.init()
+        setup()
         NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
     }
 
-    @objc func start() {
+    private func setup() {
         setupViewControllers()
         updateTheme()
     }
@@ -48,15 +43,9 @@ class VLCTabbarCooordinator: NSObject, VLCMediaCategoryViewControllerDelegate {
         }
     }
 
-    func setupViewControllers() {
-
-        tabBarController.addChildViewController(displayController)
-        tabBarController.view.addSubview(displayController.view)
-        displayController.view.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: tabBarController.tabBar.frame.size.height, right: 0)
-        displayController.didMove(toParentViewController: tabBarController)
-
+    private func setupViewControllers() {
+        // Video
         let videoVC = VLCVideoViewController(services: services)
-        videoVC.mediaDelegate = self
         videoVC.title = NSLocalizedString("VIDEO", comment: "")
         videoVC.tabBarItem = UITabBarItem(
             title: NSLocalizedString("VIDEO", comment: ""),
@@ -66,7 +55,6 @@ class VLCTabbarCooordinator: NSObject, VLCMediaCategoryViewControllerDelegate {
 
         // Audio
         let audioVC = VLCAudioViewController(services: services)
-        audioVC.mediaDelegate = self
         audioVC.title = NSLocalizedString("AUDIO", comment: "")
         audioVC.tabBarItem = UITabBarItem(
             title: NSLocalizedString("AUDIO", comment: ""),
@@ -95,16 +83,4 @@ class VLCTabbarCooordinator: NSObject, VLCMediaCategoryViewControllerDelegate {
         let controllers = [videoVC, audioVC, serverVC, settingsVC]
         tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0) }
     }
-
-    // MARK: - VLCMediaViewControllerDelegate
-
-    func mediaViewControllerDidSelectMediaObject(_ viewcontroller: UIViewController, mediaObject: NSManagedObject) {
-        playMedia(media: mediaObject)
-    }
-
-    func playMedia(media: NSManagedObject) {
-        //that should go into a Coordinator itself
-        let vpc = VLCPlaybackController.sharedInstance()
-        vpc.playMediaLibraryObject(media)
-    }
 }