MediaViewController.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. private var sortButton: UIBarButtonItem?
  17. private let fixedSpaceWidth: CGFloat = 21
  18. init(services: Services) {
  19. self.services = services
  20. rendererButton = services.rendererDiscovererManager.setupRendererButton()
  21. super.init(nibName: nil, bundle: nil)
  22. }
  23. override func viewDidLoad() {
  24. changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
  25. guard changeCurrentIndex == true else { return }
  26. oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  27. newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
  28. }
  29. setupNavigationBar()
  30. super.viewDidLoad()
  31. }
  32. private func setupNavigationBar() {
  33. if #available(iOS 11.0, *) {
  34. navigationController?.navigationBar.prefersLargeTitles = false
  35. }
  36. navigationController?.navigationBar.isTranslucent = false
  37. let fixedSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
  38. fixedSpace.width = fixedSpaceWidth
  39. sortButton = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
  40. navigationItem.leftBarButtonItem = sortButton
  41. navigationItem.rightBarButtonItems = [editButtonItem, fixedSpace, UIBarButtonItem(customView: rendererButton)]
  42. }
  43. @objc func sort() {
  44. // This should be in a subclass
  45. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  46. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) {
  47. [weak self] action in
  48. // call medialibrary
  49. if let index = self?.currentIndex {
  50. let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
  51. currentViewController?.sortByFileName()
  52. }
  53. }
  54. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) {
  55. [weak self] action in
  56. if let index = self?.currentIndex {
  57. let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
  58. currentViewController?.sortBySize()
  59. }
  60. }
  61. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) {
  62. [weak self] action in
  63. if let index = self?.currentIndex {
  64. let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
  65. currentViewController?.sortByDate()
  66. }
  67. }
  68. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  69. sortOptionsAlertController.addAction(sortByNameAction)
  70. sortOptionsAlertController.addAction(sortbyDateAction)
  71. sortOptionsAlertController.addAction(sortBySizeAction)
  72. sortOptionsAlertController.addAction(cancelAction)
  73. sortOptionsAlertController.view.tintColor = .vlcOrangeTint
  74. sortOptionsAlertController.popoverPresentationController?.sourceView = self.view
  75. present(sortOptionsAlertController, animated: true)
  76. }
  77. // MARK: - PagerTabStripDataSource
  78. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  79. fatalError("this should only be used as subclass")
  80. }
  81. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  82. cell.iconLabel.text = indicatorInfo.title
  83. }
  84. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  85. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  86. }
  87. override var preferredStatusBarStyle: UIStatusBarStyle {
  88. return PresentationTheme.current.colors.statusBarStyle
  89. }
  90. override func setEditing(_ editing: Bool, animated: Bool) {
  91. super.setEditing(editing, animated: animated)
  92. scrollingEnabled(!editing)
  93. navigationItem.leftBarButtonItem = editing ? nil : sortButton
  94. viewControllers[currentIndex].setEditing(editing, animated: animated)
  95. }
  96. }