MediaViewController.swift 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*****************************************************************************
  2. * MediaViewController.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <caro # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. import UIKit
  13. class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
  14. var services: Services
  15. private var rendererButton: UIButton
  16. init(services: Services) {
  17. self.services = services
  18. rendererButton = services.rendererDiscovererManager.setupRendererButton()
  19. super.init(nibName: nil, bundle: nil)
  20. }
  21. override func viewDidLoad() {
  22. changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
  23. guard changeCurrentIndex == true else { return }
  24. oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  25. newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
  26. }
  27. setupNavigationBar()
  28. super.viewDidLoad()
  29. }
  30. private func setupNavigationBar() {
  31. if #available(iOS 11.0, *) {
  32. navigationController?.navigationBar.prefersLargeTitles = false
  33. }
  34. navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
  35. navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
  36. }
  37. @objc func sort() {
  38. // This should be in a subclass
  39. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  40. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
  41. }
  42. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
  43. }
  44. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
  45. }
  46. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  47. sortOptionsAlertController.addAction(sortByNameAction)
  48. sortOptionsAlertController.addAction(sortbyDateAction)
  49. sortOptionsAlertController.addAction(sortBySizeAction)
  50. sortOptionsAlertController.addAction(cancelAction)
  51. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  52. present(sortOptionsAlertController, animated: true)
  53. }
  54. // MARK: - PagerTabStripDataSource
  55. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  56. fatalError("this should only be used as subclass")
  57. }
  58. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  59. cell.iconLabel.text = indicatorInfo.title
  60. }
  61. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  62. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  63. }
  64. override var preferredStatusBarStyle: UIStatusBarStyle {
  65. return PresentationTheme.current.colors.statusBarStyle
  66. }
  67. }
  68. // MARK: - VLCMediaCategoryViewControllerDelegate
  69. extension VLCMediaViewController: VLCMediaCategoryViewControllerDelegate {
  70. func mediaViewControllerDidSelectMediaObject(_ viewcontroller: UIViewController, mediaObject: NSManagedObject) {
  71. playMedia(media: mediaObject)
  72. }
  73. func playMedia(media: NSManagedObject) {
  74. //that should go into a Coordinator itself
  75. let vpc = VLCPlaybackController.sharedInstance()
  76. vpc?.playMediaLibraryObject(media)
  77. }
  78. }