Commit 2a2cbca2 authored by Carola Nitz's avatar Carola Nitz

Renaming for more clarity

parent fc41a9c8
/*****************************************************************************
* MediaCateogoryViewController.swift
* VLC for iOS
*****************************************************************************
* Copyright (c) 2018 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # gmail.com>
* Mike JS. Choi <mkchoi212 # icloud.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
import Foundation
protocol VLCMediaCategoryViewControllerDelegate: class {
func mediaViewControllerDidSelectMediaObject(_ mediaViewController: UIViewController, mediaObject: NSManagedObject)
}
class VLCMediaCategoryViewController<T>: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchResultsUpdating, UISearchControllerDelegate, IndicatorInfoProvider {
let cellPadding: CGFloat = 5.0
private var services: Services
private var searchController: UISearchController?
private let searchDataSource = VLCLibrarySearchDisplayDataSource()
var subcategory: VLCMediaSubcategoryModel<T>
weak var delegate: VLCMediaCategoryViewControllerDelegate?
@available(iOS 11.0, *)
lazy var dragAndDropManager: VLCDragAndDropManager = { () -> VLCDragAndDropManager<T> in
VLCDragAndDropManager<T>(subcategory: subcategory)
}()
lazy var emptyView: VLCEmptyLibraryView = {
let name = String(describing: VLCEmptyLibraryView.self)
let nib = Bundle.main.loadNibNamed(name, owner: self, options: nil)
guard let emptyView = nib?.first as? VLCEmptyLibraryView else { fatalError("Can't find nib for \(name)") }
return emptyView
}()
@available(*, unavailable)
init() {
fatalError()
}
init(services: Services, subcategory: VLCMediaSubcategoryModel<T>) {
self.services = services
self.subcategory = subcategory
super.init(collectionViewLayout: UICollectionViewFlowLayout())
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: subcategory.changeNotificationName, object: nil)
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return PresentationTheme.current.colors.statusBarStyle
}
@objc func reloadData() {
collectionView?.reloadData()
updateUIForContent()
}
@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder: ) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
setupCollectionView()
setupSearchController()
_ = (MLMediaLibrary.sharedMediaLibrary() as! MLMediaLibrary).libraryDidAppear()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let manager = services.rendererDiscovererManager
if manager.discoverers.isEmpty {
// Either didn't start or stopped before
manager.start()
}
manager.presentingViewController = self
}
@objc func themeDidChange() {
collectionView?.backgroundColor = PresentationTheme.current.colors.background
setNeedsStatusBarAppearanceUpdate()
}
func setupCollectionView() {
let playlistnib = UINib(nibName: "VLCPlaylistCollectionViewCell", bundle: nil)
collectionView?.register(playlistnib, forCellWithReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier())
collectionView?.backgroundColor = PresentationTheme.current.colors.background
collectionView?.alwaysBounceVertical = true
if #available(iOS 11.0, *) {
collectionView?.dragDelegate = dragAndDropManager
collectionView?.dropDelegate = dragAndDropManager
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
reloadData()
}
func setupSearchController() {
searchController = UISearchController(searchResultsController: nil)
searchController?.searchResultsUpdater = self
searchController?.dimsBackgroundDuringPresentation = false
searchController?.delegate = self
if let textfield = searchController?.searchBar.value(forKey: "searchField") as? UITextField {
if let backgroundview = textfield.subviews.first {
backgroundview.backgroundColor = UIColor.white
backgroundview.layer.cornerRadius = 10
backgroundview.clipsToBounds = true
}
}
}
func updateUIForContent() {
let isEmpty = collectionView?.numberOfItems(inSection: 0) == 0
if isEmpty {
collectionView?.setContentOffset(.zero, animated: false)
}
collectionView?.backgroundView = isEmpty ? emptyView : nil
if #available(iOS 11.0, *) {
navigationItem.searchController = isEmpty ? nil : searchController
} else {
navigationItem.titleView = isEmpty ? nil : searchController?.searchBar
}
}
// MARK: Renderer
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
collectionView?.collectionViewLayout.invalidateLayout()
}
// MARK: - Search
func updateSearchResults(for searchController: UISearchController) {
searchDataSource.shouldReloadTable(forSearch: searchController.searchBar.text, searchableFiles: subcategory.files)
collectionView?.reloadData()
}
func didPresentSearchController(_ searchController: UISearchController) {
collectionView?.dataSource = searchDataSource
}
func didDismissSearchController(_ searchController: UISearchController) {
collectionView?.dataSource = self
}
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title:subcategory.indicatorInfoName)
}
// MARK: - UICollectionViewDataSource
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return subcategory.files.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let playlistCell = collectionView.dequeueReusableCell(withReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier(), for: indexPath) as? VLCPlaylistCollectionViewCell {
if let mediaObject = subcategory.files[indexPath.row] as? NSManagedObject {
playlistCell.mediaObject = mediaObject
}
return playlistCell
}
return UICollectionViewCell()
}
// MARK: - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let mediaObject = subcategory.files[indexPath.row] 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
let aspectRatio: CGFloat = 10.0 / 16.0
// We have the number of cells and we always have numberofCells + 1 padding spaces. -pad-[Cell]-pad-[Cell]-pad-
// we then have the entire padding, we divide the entire padding by the number of Cells to know how much needs to be substracted from ech cell
// since this might be an uneven number we ceil
var cellWidth = collectionView.bounds.size.width / numberOfCells
cellWidth = cellWidth - ceil(((numberOfCells + 1) * cellPadding) / numberOfCells)
return CGSize(width: cellWidth, height: cellWidth * aspectRatio)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: cellPadding, left: cellPadding, bottom: cellPadding, right: cellPadding)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return cellPadding
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return cellPadding
}
}
......@@ -30,10 +30,10 @@ enum VLCDataUnit {
case label(MLLabel)
}
class VLCMediaSubcategory<T>: NSObject {
class VLCMediaSubcategoryModel<T>: NSObject {
var files: [T]
var indicatorInfoName: String
var notificationName: Notification.Name
var changeNotificationName: Notification.Name
var includesFunc: (VLCDataUnit) -> Bool
var appendFunc: (VLCDataUnit) -> Void
......@@ -48,14 +48,14 @@ class VLCMediaSubcategory<T>: NSObject {
appendFunc: @escaping (VLCDataUnit) -> Void) {
self.files = files
self.indicatorInfoName = indicatorInfoName
self.notificationName = notificationName
self.changeNotificationName = notificationName
self.includesFunc = includesFunc
self.appendFunc = appendFunc
}
}
struct VLCMediaSubcategories {
static var movies = VLCMediaSubcategory<MLFile>(
static var movies = VLCMediaSubcategoryModel<MLFile>(
files: {
(MLFile.allFiles() as! [MLFile]).filter {
($0 as MLFile).isKind(ofType: kMLFileTypeMovie) ||
......@@ -75,7 +75,7 @@ struct VLCMediaSubcategories {
})
static var episodes = VLCMediaSubcategory<MLShowEpisode>(
static var episodes = VLCMediaSubcategoryModel<MLShowEpisode>(
files: MLShowEpisode.allEpisodes() as! [MLShowEpisode],
indicatorInfoName: NSLocalizedString("EPISODES", comment: ""),
notificationName: .VLCEpisodesDidChangeNotification,
......@@ -89,7 +89,7 @@ struct VLCMediaSubcategories {
})
static var artists = VLCMediaSubcategory<String>(
static var artists = VLCMediaSubcategoryModel<String>(
files: {
let tracksWithArtist = (MLAlbumTrack.allTracks() as! [MLAlbumTrack]).filter { $0.artist != nil && $0.artist != "" }
return tracksWithArtist.map { $0.artist } as! [String]
......@@ -106,7 +106,7 @@ struct VLCMediaSubcategories {
})
static var albums = VLCMediaSubcategory<MLAlbum>(
static var albums = VLCMediaSubcategoryModel<MLAlbum>(
files: MLAlbum.allAlbums() as! [MLAlbum],
indicatorInfoName: NSLocalizedString("ALBUMS", comment: ""),
notificationName: .VLCAlbumsDidChangeNotification,
......@@ -120,7 +120,7 @@ struct VLCMediaSubcategories {
})
static var tracks = VLCMediaSubcategory<MLFile>(
static var tracks = VLCMediaSubcategoryModel<MLFile>(
files: (MLFile.allFiles() as! [MLFile]).filter { $0.isSupportedAudioFile()},
indicatorInfoName: NSLocalizedString("SONGS", comment: ""),
notificationName: .VLCTracksDidChangeNotification,
......@@ -134,7 +134,7 @@ struct VLCMediaSubcategories {
})
static var genres = VLCMediaSubcategory<String>(
static var genres = VLCMediaSubcategoryModel<String>(
files: {
let albumtracks = MLAlbumTrack.allTracks() as! [MLAlbumTrack]
let tracksWithArtist = albumtracks.filter { $0.genre != nil && $0.genre != "" }
......@@ -152,7 +152,7 @@ struct VLCMediaSubcategories {
})
static var audioPlaylists = VLCMediaSubcategory<MLLabel>(
static var audioPlaylists = VLCMediaSubcategoryModel<MLLabel>(
files: {
let labels = MLLabel.allLabels() as! [MLLabel]
let audioPlaylist = labels.filter {
......@@ -185,7 +185,7 @@ struct VLCMediaSubcategories {
})
static var videoPlaylists = VLCMediaSubcategory<MLLabel>(
static var videoPlaylists = VLCMediaSubcategoryModel<MLLabel>(
files: {
let labels = MLLabel.allLabels() as! [MLLabel]
let audioPlaylist = labels.filter {
......
/*****************************************************************************
* MediaSubcategoryViewController.swift
* VLC for iOS
*****************************************************************************
* Copyright (c) 2018 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <caro # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
import UIKit
class VLCVideoSubcategoryViewController: VLCMediaSubcategoryViewController {
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let movies = VLCMediaViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.movies)
movies.delegate = mediaDelegate
let episodes = VLCMediaViewController<MLShowEpisode>(services: services, subcategory: VLCMediaSubcategories.episodes)
episodes.delegate = mediaDelegate
let playlists = VLCMediaViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.videoPlaylists)
playlists.delegate = mediaDelegate
return [movies, episodes, playlists]
}
}
class VLCAudioSubcategoryViewController: VLCMediaSubcategoryViewController {
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let tracks = VLCMediaViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.tracks)
tracks.delegate = mediaDelegate
let genres = VLCMediaViewController<String>(services: services, subcategory: VLCMediaSubcategories.genres)
genres.delegate = mediaDelegate
let artists = VLCMediaViewController<String>(services: services, subcategory: VLCMediaSubcategories.artists)
artists.delegate = mediaDelegate
let albums = VLCMediaViewController<MLAlbum>(services: services, subcategory: VLCMediaSubcategories.albums)
albums.delegate = mediaDelegate
let playlists = VLCMediaViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.audioPlaylists)
playlists.delegate = mediaDelegate
return [tracks, genres, artists, albums, playlists]
}
}
class VLCMediaSubcategoryViewController: BaseButtonBarPagerTabStripViewController<VLCLabelCell> {
var services: Services
weak var mediaDelegate: VLCMediaViewControllerDelegate?
private var rendererButton: UIButton
init(services: Services) {
self.services = services
rendererButton = services.rendererDiscovererManager.setupRendererButton()
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
guard changeCurrentIndex == true else { return }
oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
}
setupNavigationBar()
super.viewDidLoad()
}
private func setupNavigationBar() {
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = false
}
navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
}
@objc func sort() {
// This should be in a subclass
let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
}
let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
}
let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
}
let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
sortOptionsAlertController.addAction(sortByNameAction)
sortOptionsAlertController.addAction(sortbyDateAction)
sortOptionsAlertController.addAction(sortBySizeAction)
sortOptionsAlertController.addAction(cancelAction)
sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
present(sortOptionsAlertController, animated: true)
}
// MARK: - PagerTabStripDataSource
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
fatalError("this should only be used as subclass")
}
override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
cell.iconLabel.text = indicatorInfo.title
}
override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return PresentationTheme.current.colors.statusBarStyle
}
}
......@@ -5,205 +5,105 @@
* Copyright (c) 2018 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # gmail.com>
* Mike JS. Choi <mkchoi212 # icloud.com>
* Authors: Carola Nitz <caro # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
import Foundation
import UIKit
protocol VLCMediaViewControllerDelegate: class {
func mediaViewControllerDidSelectMediaObject(_ mediaViewController: UIViewController, mediaObject: NSManagedObject)
}
class VLCMediaViewController<T>: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchResultsUpdating, UISearchControllerDelegate, IndicatorInfoProvider {
let cellPadding: CGFloat = 5.0
private var services: Services
private var searchController: UISearchController?
private let searchDataSource = VLCLibrarySearchDisplayDataSource()
var subcategory: VLCMediaSubcategory<T>
weak var delegate: VLCMediaViewControllerDelegate?
@available(iOS 11.0, *)
lazy var dragAndDropManager: VLCDragAndDropManager = { () -> VLCDragAndDropManager<T> in
VLCDragAndDropManager<T>(subcategory: subcategory)
}()
lazy var emptyView: VLCEmptyLibraryView = {
let name = String(describing: VLCEmptyLibraryView.self)
let nib = Bundle.main.loadNibNamed(name, owner: self, options: nil)
guard let emptyView = nib?.first as? VLCEmptyLibraryView else { fatalError("Can't find nib for \(name)") }
return emptyView
}()
@available(*, unavailable)
init() {
fatalError()
class VLCVideoViewController: VLCMediaViewController {
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let movies = VLCMediaCategoryViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.movies)
movies.delegate = mediaDelegate
let episodes = VLCMediaCategoryViewController<MLShowEpisode>(services: services, subcategory: VLCMediaSubcategories.episodes)
episodes.delegate = mediaDelegate
let playlists = VLCMediaCategoryViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.videoPlaylists)
playlists.delegate = mediaDelegate
return [movies, episodes, playlists]
}
}
init(services: Services, subcategory: VLCMediaSubcategory<T>) {
self.services = services
self.subcategory = subcategory
super.init(collectionViewLayout: UICollectionViewFlowLayout())
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: subcategory.notificationName, object: nil)
class VLCAudioViewController: VLCMediaViewController {
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let tracks = VLCMediaCategoryViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.tracks)
tracks.delegate = mediaDelegate
let genres = VLCMediaCategoryViewController<String>(services: services, subcategory: VLCMediaSubcategories.genres)
genres.delegate = mediaDelegate
let artists = VLCMediaCategoryViewController<String>(services: services, subcategory: VLCMediaSubcategories.artists)
artists.delegate = mediaDelegate
let albums = VLCMediaCategoryViewController<MLAlbum>(services: services, subcategory: VLCMediaSubcategories.albums)
albums.delegate = mediaDelegate
let playlists = VLCMediaCategoryViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.audioPlaylists)
playlists.delegate = mediaDelegate
return [tracks, genres, artists, albums, playlists]
}
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return PresentationTheme.current.colors.statusBarStyle
}
class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
@objc func reloadData() {
collectionView?.reloadData()
updateUIForContent()
}
var services: Services
weak var mediaDelegate: VLCMediaCategoryViewControllerDelegate?
private var rendererButton: UIButton
@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder: ) has not been implemented")
init(services: Services) {
self.services = services
rendererButton = services.rendererDiscovererManager.setupRendererButton()
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
setupCollectionView()
setupSearchController()
_ = (MLMediaLibrary.sharedMediaLibrary() as! MLMediaLibrary).libraryDidAppear()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let manager = services.rendererDiscovererManager
if manager.discoverers.isEmpty {
// Either didn't start or stopped before
manager.start()
changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
guard changeCurrentIndex == true else { return }
oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
}
manager.presentingViewController = self
}
@objc func themeDidChange() {
collectionView?.backgroundColor = PresentationTheme.current.colors.background
setNeedsStatusBarAppearanceUpdate()
setupNavigationBar()
super.viewDidLoad()
}
func setupCollectionView() {
let playlistnib = UINib(nibName: "VLCPlaylistCollectionViewCell", bundle: nil)
collectionView?.register(playlistnib, forCellWithReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier())
collectionView?.backgroundColor = PresentationTheme.current.colors.background
collectionView?.alwaysBounceVertical = true
private func setupNavigationBar() {
if #available(iOS 11.0, *) {
collectionView?.dragDelegate = dragAndDropManager
collectionView?.dropDelegate = dragAndDropManager
navigationController?.navigationBar.prefersLargeTitles = false
}
navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
reloadData()
}
func setupSearchController() {
searchController = UISearchController(searchResultsController: nil)
searchController?.searchResultsUpdater = self
searchController?.dimsBackgroundDuringPresentation = false
searchController?.delegate = self
if let textfield = searchController?.searchBar.value(forKey: "searchField") as? UITextField {
if let backgroundview = textfield.subviews.first {
backgroundview.backgroundColor = UIColor.white
backgroundview.layer.cornerRadius = 10
backgroundview.clipsToBounds = true
}
}
}
func updateUIForContent() {
let isEmpty = collectionView?.numberOfItems(inSection: 0) == 0
if isEmpty {
collectionView?.setContentOffset(.zero, animated: false)
@objc func sort() {
// This should be in a subclass
let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
}
collectionView?.backgroundView = isEmpty ? emptyView : nil
if #available(iOS 11.0, *) {
navigationItem.searchController = isEmpty ? nil : searchController
} else {
navigationItem.titleView = isEmpty ? nil : searchController?.searchBar
}
}
// MARK: Renderer
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
collectionView?.collectionViewLayout.invalidateLayout()
}
// MARK: - Search
func updateSearchResults(for searchController: UISearchController) {
searchDataSource.shouldReloadTable(forSearch: searchController.searchBar.text, searchableFiles: subcategory.files)
collectionView?.reloadData()
}
func didPresentSearchController(_ searchController: UISearchController) {
collectionView?.dataSource = searchDataSource
}
func didDismissSearchController(_ searchController: UISearchController) {
collectionView?.dataSource = self
}
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title:subcategory.indicatorInfoName)
}
// MARK: - UICollectionViewDataSource
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return subcategory.files.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let playlistCell = collectionView.dequeueReusableCell(withReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier(), for: indexPath) as? VLCPlaylistCollectionViewCell {
if let mediaObject = subcategory.files[indexPath.row] as? NSManagedObject {
playlistCell.mediaObject = mediaObject
}
return playlistCell
let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
}
return UICollectionViewCell()
}
// MARK: - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let mediaObject = subcategory.files[indexPath.row] as? NSManagedObject {
delegate?.mediaViewControllerDidSelectMediaObject(self, mediaObject: mediaObject)
let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
}
let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
sortOptionsAlertController.addAction(sortByNameAction)
sortOptionsAlertController.addAction(sortbyDateAction)
sortOptionsAlertController.addAction(sortBySizeAction)
sortOptionsAlertController.addAction(cancelAction)
sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
present(sortOptionsAlertController, animated: true)
}
// MARK: - UICollectionViewDelegateFlowLayout
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// MARK: - PagerTabStripDataSource
let numberOfCells: CGFloat = collectionView.traitCollection.horizontalSizeClass == .regular ? 3.0 : 2.0
let aspectRatio: CGFloat = 10.0 / 16.0
// We have the number of cells and we always have numberofCells + 1 padding spaces. -pad-[Cell]-pad-[Cell]-pad-
// we then have the entire padding, we divide the entire padding by the number of Cells to know how much needs to be substracted from ech cell
// since this might be an uneven number we ceil
var cellWidth = collectionView.bounds.size.width / numberOfCells
cellWidth = cellWidth - ceil(((numberOfCells + 1) * cellPadding) / numberOfCells)
return CGSize(width: cellWidth, height: cellWidth * aspectRatio)
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
fatalError("this should only be used as subclass")
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: cellPadding, left: cellPadding, bottom: cellPadding, right: cellPadding)
override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
cell.iconLabel.text = indicatorInfo.title
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return cellPadding
override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return cellPadding
override var preferredStatusBarStyle: UIStatusBarStyle {
return PresentationTheme.current.colors.statusBarStyle
}
}
......@@ -36,7 +36,7 @@ protocol VLCDragAndDropManagerDelegate: NSObjectProtocol {
class VLCDragAndDropManager<T>: NSObject, UICollectionViewDragDelegate, UITableViewDragDelegate, UICollectionViewDropDelegate, UITableViewDropDelegate, UIDropInteractionDelegate {
let utiTypeIdentifiers: [String] = VLCDragAndDropManager.supportedTypeIdentifiers()
var subcategory: VLCMediaSubcategory<T>
var subcategory: VLCMediaSubcategoryModel<T>