VLCEditController.swift 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*****************************************************************************
  2. * VLCEditController.swift
  3. *
  4. * Copyright © 2018 VLC authors and VideoLAN
  5. * Copyright © 2018 Videolabs
  6. *
  7. * Authors: Soomin Lee <bubu@mikan.io>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. protocol VLCEditControllerDataSource {
  12. func toolbarNeedsUpdate(editing: Bool)
  13. }
  14. class VLCEditController: NSObject {
  15. private let collectionView: UICollectionView
  16. private let category: MediaLibraryBaseModel
  17. private lazy var editToolbar: VLCEditToolbar = {
  18. let editToolbar = VLCEditToolbar(frame: CGRect(x: 0, y: 550,
  19. width: collectionView.frame.width, height: 50))
  20. editToolbar.isHidden = true
  21. editToolbar.delegate = self
  22. return editToolbar
  23. }()
  24. init(collectionView: UICollectionView, category: MediaLibraryBaseModel) {
  25. self.collectionView = collectionView
  26. self.category = category
  27. super.init()
  28. collectionView.addSubview(editToolbar)
  29. collectionView.bringSubview(toFront: editToolbar)
  30. }
  31. }
  32. extension VLCEditController: VLCEditControllerDataSource {
  33. func toolbarNeedsUpdate(editing: Bool) {
  34. editToolbar.isHidden = !editing
  35. }
  36. }
  37. extension VLCEditController: VLCEditToolbarDelegate {
  38. func createPlaylist() {
  39. }
  40. func delete() {
  41. }
  42. func rename() {
  43. }
  44. }
  45. extension VLCEditController: UICollectionViewDataSource {
  46. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  47. return category.anyfiles.count
  48. }
  49. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  50. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: VLCMediaViewEditCell.identifier,
  51. for: indexPath) as? VLCMediaViewEditCell {
  52. cell.titleLabel.text = "( `ー´)ノ"
  53. cell.subInfoLabel.text = "(-ω-、)"
  54. cell.sizeLabel.text = "|ω°•)"
  55. cell.thumbnailImageView.image = UIImage(named: "vlc-xmas")
  56. return cell
  57. }
  58. return UICollectionViewCell()
  59. }
  60. }
  61. extension VLCEditController: UICollectionViewDelegate {
  62. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  63. if let cell = collectionView.cellForItem(at: indexPath) as? VLCMediaViewEditCell {
  64. cell.checkView.isEnabled = !cell.checkView.isEnabled
  65. }
  66. }
  67. }
  68. extension VLCEditController: UICollectionViewDelegateFlowLayout {
  69. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  70. let contentInset = collectionView.contentInset
  71. // FIXME: 5 should be cell padding, but not usable maybe static?
  72. let insetToRemove = contentInset.left + contentInset.right + (5 * 2)
  73. return CGSize(width: collectionView.frame.width - insetToRemove, height: VLCMediaViewEditCell.height)
  74. }
  75. }