Commit 7d97985b authored by Carola Nitz's avatar Carola Nitz

MediaViewController: Delete the MediaDataSourceAndDelegate and move functions into extension

parent 09e252f0
/*****************************************************************************
* MediaDataSourceAndDelegate.swift
* MediaViewController+DataSourceDelegate.swift
* VLC for iOS
*****************************************************************************
* Copyright (c) 2018 VideoLAN. All rights reserved.
......@@ -10,34 +10,21 @@
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
extension Notification.Name {
static let VLCTracksDidChangeNotification = Notification.Name("kTracksDidChangeNotification")
static let VLCAllVideosDidChangeNotification = Notification.Name("kAllVideosDidChangeNotification")
}
class MediaDataSourceAndDelegate: NSObject, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
private let cellPadding: CGFloat = 5.0
private var services: Services
private var mediaType: VLCMediaType
weak var delegate: UICollectionViewDelegate?
@available(*, unavailable)
override init() {
fatalError()
}
// These are the delegate and datasource calls from the MediaViewController
extension VLCMediaViewController: UICollectionViewDelegateFlowLayout {
init(services: Services, type: VLCMediaType) {
self.services = services
mediaType = type
super.init()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// MARK: - UICollectionViewDataSource
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return Int(services.mediaDataSource.numberOfFiles(subcategory: mediaType.subcategory))
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let playlistCell = collectionView.dequeueReusableCell(withReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier(), for: indexPath) as? VLCPlaylistCollectionViewCell {
if let mediaObject = services.mediaDataSource.object(at: indexPath.row, subcategory: mediaType.subcategory) as? NSManagedObject {
playlistCell.mediaObject = mediaObject
......@@ -47,10 +34,14 @@ class MediaDataSourceAndDelegate: NSObject, UICollectionViewDataSource, UICollec
return UICollectionViewCell()
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
delegate?.collectionView!(collectionView, didSelectItemAt: indexPath)
// MARK: - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let mediaObject = services.mediaDataSource.object(at: indexPath.row, subcategory: mediaType.subcategory) as? NSManagedObject {
delegate?.mediaViewControllerDidSelectMediaObject(self, mediaObject: mediaObject)
}
}
// MARK: - UICollectionViewDelegateFlowLayout
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let numberOfCells: CGFloat = collectionView.traitCollection.horizontalSizeClass == .regular ? 3.0 : 2.0
......
......@@ -18,13 +18,12 @@ import Foundation
}
class VLCMediaViewController: UICollectionViewController, UISearchResultsUpdating, UISearchControllerDelegate, IndicatorInfoProvider {
private var services: Services
private var mediaDataSourceAndDelegate: MediaDataSourceAndDelegate?
let cellPadding: CGFloat = 5.0
var services: Services
var mediaType: VLCMediaType
weak var delegate: VLCMediaViewControllerDelegate?
private var searchController: UISearchController?
private let searchDataSource = VLCLibrarySearchDisplayDataSource()
private var mediaType: VLCMediaType
weak var delegate: VLCMediaViewControllerDelegate?
@available(iOS 11.0, *)
lazy var dragAndDropManager: VLCDragAndDropManager = {
......@@ -95,14 +94,12 @@ class VLCMediaViewController: UICollectionViewController, UISearchResultsUpdatin
}
func setupCollectionView() {
mediaDataSourceAndDelegate = MediaDataSourceAndDelegate(services: services, type: mediaType)
mediaDataSourceAndDelegate?.delegate = self
let playlistnib = UINib(nibName: "VLCPlaylistCollectionViewCell", bundle: nil)
collectionView?.register(playlistnib, forCellWithReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier())
collectionView?.backgroundColor = PresentationTheme.current.colors.background
collectionView?.alwaysBounceVertical = true
collectionView?.dataSource = mediaDataSourceAndDelegate
collectionView?.delegate = mediaDataSourceAndDelegate
collectionView?.dataSource = self
collectionView?.delegate = self
if #available(iOS 11.0, *) {
collectionView?.dragDelegate = dragAndDropManager
collectionView?.dropDelegate = dragAndDropManager
......@@ -149,14 +146,6 @@ class VLCMediaViewController: UICollectionViewController, UISearchResultsUpdatin
collectionView?.collectionViewLayout.invalidateLayout()
}
// MARK: - MediaDatasourceAndDelegate
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let mediaObject = services.mediaDataSource.object(at: indexPath.row, subcategory: mediaType.subcategory) as? NSManagedObject {
delegate?.mediaViewControllerDidSelectMediaObject(self, mediaObject: mediaObject)
}
}
// MARK: - Search
func updateSearchResults(for searchController: UISearchController) {
......@@ -169,7 +158,7 @@ class VLCMediaViewController: UICollectionViewController, UISearchResultsUpdatin
}
func didDismissSearchController(_ searchController: UISearchController) {
collectionView?.dataSource = mediaDataSourceAndDelegate
collectionView?.dataSource = self
}
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
......
......@@ -37,10 +37,10 @@
418B145620179DF2000447AA /* VLCMediaData+VLCDragAndDrop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 418B145520179DF2000447AA /* VLCMediaData+VLCDragAndDrop.swift */; };
418B145920179E50000447AA /* VLCDragAndDropManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 418B145820179E50000447AA /* VLCDragAndDropManager.swift */; };
4195747D206A92ED00393A42 /* RemoteNetworkDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4195747C206A92ED00393A42 /* RemoteNetworkDataSource.swift */; };
419794C3206B9E7A009E081A /* MediaDataSourceAndDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419794C2206B9E7A009E081A /* MediaDataSourceAndDelegate.swift */; };
419A2C661F37A4B70069D224 /* VLCStringsForLocalization.m in Sources */ = {isa = PBXBuildFile; fileRef = 419A2C651F37A4B70069D224 /* VLCStringsForLocalization.m */; };
419A2C681F37A4B70069D224 /* VLCStringsForLocalization.m in Sources */ = {isa = PBXBuildFile; fileRef = 419A2C651F37A4B70069D224 /* VLCStringsForLocalization.m */; };
419D7F051F54176900AF69A2 /* VLCTimeNavigationTitleView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 419D7F041F54176900AF69A2 /* VLCTimeNavigationTitleView.xib */; };
41A6948320EFAC090070151D /* MediaViewController+DataSourceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41A6948220EFAC090070151D /* MediaViewController+DataSourceDelegate.swift */; };
41B93C011A53833B00102E8B /* VLCProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = 41B93C001A53833B00102E8B /* VLCProgressView.m */; };
41B93C051A53835300102E8B /* VLCCloudServiceCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 41B93C031A53835300102E8B /* VLCCloudServiceCell.m */; };
41B93C081A53853B00102E8B /* VLCCloudServiceCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41B93C071A53853B00102E8B /* VLCCloudServiceCell.xib */; };
......@@ -564,9 +564,9 @@
418B145520179DF2000447AA /* VLCMediaData+VLCDragAndDrop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "VLCMediaData+VLCDragAndDrop.swift"; path = "Sources/VLCMediaData+VLCDragAndDrop.swift"; sourceTree = "<group>"; };
418B145820179E50000447AA /* VLCDragAndDropManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VLCDragAndDropManager.swift; path = Sources/VLCDragAndDropManager.swift; sourceTree = "<group>"; };
4195747C206A92ED00393A42 /* RemoteNetworkDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteNetworkDataSource.swift; sourceTree = "<group>"; };
419794C2206B9E7A009E081A /* MediaDataSourceAndDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaDataSourceAndDelegate.swift; sourceTree = "<group>"; };
419A2C651F37A4B70069D224 /* VLCStringsForLocalization.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCStringsForLocalization.m; sourceTree = "<group>"; };
419D7F041F54176900AF69A2 /* VLCTimeNavigationTitleView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = VLCTimeNavigationTitleView.xib; path = Resources/VLCTimeNavigationTitleView.xib; sourceTree = SOURCE_ROOT; };
41A6948220EFAC090070151D /* MediaViewController+DataSourceDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "MediaViewController+DataSourceDelegate.swift"; path = "Sources/MediaViewController+DataSourceDelegate.swift"; sourceTree = SOURCE_ROOT; };
41B0BC861F73ED7D0063BA26 /* VLC for iOSUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "VLC for iOSUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
41B0BC8A1F73ED7D0063BA26 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
41B93BFF1A53833B00102E8B /* VLCProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCProgressView.h; path = Sources/VLCProgressView.h; sourceTree = SOURCE_ROOT; };
......@@ -1938,7 +1938,7 @@
7D37849D183A98DD009EE944 /* VLCThumbnailsCache.m */,
DD7110EE1AF38B2B00854776 /* MLMediaLibrary+playlist.h */,
DD7110EF1AF38B2B00854776 /* MLMediaLibrary+playlist.m */,
419794C2206B9E7A009E081A /* MediaDataSourceAndDelegate.swift */,
41A6948220EFAC090070151D /* MediaViewController+DataSourceDelegate.swift */,
);
name = Library;
sourceTree = "<group>";
......@@ -3232,6 +3232,7 @@
7D3784AE183A9906009EE944 /* VLCDropboxTableViewController.m in Sources */,
7D3784BE183A9938009EE944 /* UIBarButtonItem+Theme.m in Sources */,
DD3EFF3B1BDEBCE500B68579 /* VLCNetworkServerBrowserVLCMedia.m in Sources */,
41A6948320EFAC090070151D /* MediaViewController+DataSourceDelegate.swift in Sources */,
41B93C051A53835300102E8B /* VLCCloudServiceCell.m in Sources */,
7D4625881A5614A1001A80B4 /* VLCEqualizerView.m in Sources */,
7DF9352F1958AB0600E60FD4 /* UIColor+Presets.m in Sources */,
......@@ -3249,7 +3250,6 @@
7D3784C8183A9972009EE944 /* NSString+SupportedMedia.m in Sources */,
417E68B91F321EFF00DB9BB2 /* VLCActivityViewControllerVendor.m in Sources */,
DD3EFF5B1BDEBCE500B68579 /* VLCNetworkServerBrowserUPnP.m in Sources */,
419794C3206B9E7A009E081A /* MediaDataSourceAndDelegate.swift in Sources */,
8DD651BA208F6AF00052EE68 /* VLCActionSheetCell.swift in Sources */,
418B144D20179C75000447AA /* VLCTabBarCoordinator.swift in Sources */,
DD3EABF81BE14BD6003668DA /* BasicUPnPDevice+VLC.m in Sources */,
......
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