VLCEditController.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. return editToolbar
  22. }()
  23. init(collectionView: UICollectionView, category: MediaLibraryBaseModel) {
  24. self.collectionView = collectionView
  25. self.category = category
  26. super.init()
  27. collectionView.addSubview(editToolbar)
  28. collectionView.bringSubview(toFront: editToolbar)
  29. }
  30. }
  31. extension VLCEditController: VLCEditControllerDataSource {
  32. func toolbarNeedsUpdate(editing: Bool) {
  33. editToolbar.isHidden = !editing
  34. }
  35. }
  36. extension VLCEditController: UICollectionViewDataSource {
  37. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  38. return category.anyfiles.count
  39. }
  40. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  41. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: VLCMediaViewEditCell.identifier,
  42. for: indexPath) as? VLCMediaViewEditCell {
  43. cell.titleLabel.text = "( `ー´)ノ"
  44. cell.subInfoLabel.text = "(-ω-、)"
  45. cell.sizeLabel.text = "|ω°•)"
  46. cell.thumbnailImageView.image = UIImage(named: "vlc-xmas")
  47. return cell
  48. }
  49. return UICollectionViewCell()
  50. }
  51. }
  52. extension VLCEditController: UICollectionViewDelegate {
  53. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  54. if let cell = collectionView.cellForItem(at: indexPath) as? VLCMediaViewEditCell {
  55. cell.checkView.isEnabled = !cell.checkView.isEnabled
  56. }
  57. }
  58. }
  59. extension VLCEditController: UICollectionViewDelegateFlowLayout {
  60. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  61. let contentInset = collectionView.contentInset
  62. // FIXME: 5 should be cell padding, but not usable maybe static?
  63. let insetToRemove = contentInset.left + contentInset.right + (5 * 2)
  64. return CGSize(width: collectionView.frame.width - insetToRemove, height: VLCMediaViewEditCell.height)
  65. }
  66. }