MediaViewController.swift 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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) {
  41. [weak self] action in
  42. // call medialibrary
  43. if let index = self?.currentIndex {
  44. let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
  45. currentViewController?.sortByFileName()
  46. }
  47. }
  48. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) {
  49. [weak self] action in
  50. if let index = self?.currentIndex {
  51. let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
  52. currentViewController?.sortBySize()
  53. }
  54. }
  55. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) {
  56. [weak self] action in
  57. if let index = self?.currentIndex {
  58. let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
  59. currentViewController?.sortByDate()
  60. }
  61. }
  62. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  63. sortOptionsAlertController.addAction(sortByNameAction)
  64. sortOptionsAlertController.addAction(sortbyDateAction)
  65. sortOptionsAlertController.addAction(sortBySizeAction)
  66. sortOptionsAlertController.addAction(cancelAction)
  67. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  68. sortOptionsAlertController.popoverPresentationController?.sourceView = self.view
  69. present(sortOptionsAlertController, animated: true)
  70. }
  71. // MARK: - PagerTabStripDataSource
  72. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  73. fatalError("this should only be used as subclass")
  74. }
  75. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  76. cell.iconLabel.text = indicatorInfo.title
  77. }
  78. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  79. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  80. }
  81. override var preferredStatusBarStyle: UIStatusBarStyle {
  82. return PresentationTheme.current.colors.statusBarStyle
  83. }
  84. }