MediaEditCell.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*****************************************************************************
  2. * VLCMediaViewEditCell.swift
  3. *
  4. * Copyright © 2018 VLC authors and VideoLAN
  5. * Copyright © 2018 Videolabs
  6. *
  7. * Authors: Soomin Lee <bubu@mikan.io>
  8. * Carola Nitz <nitz.carola@googlemail.com>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. class MediaEditCell: BaseCollectionViewCell {
  13. static let height: CGFloat = 88
  14. @IBOutlet weak var checkboxImageView: UIImageView!
  15. @IBOutlet weak var thumbnailImageView: UIImageView!
  16. @IBOutlet weak var titleLabel: UILabel!
  17. @IBOutlet weak var timeLabel: UILabel!
  18. @IBOutlet weak var sizeLabel: UILabel!
  19. override var media: VLCMLObject? {
  20. didSet {
  21. guard let media = media as? VLCMLMedia else {
  22. fatalError("needs to be of Type VLCMLMedia")
  23. }
  24. update(media:media)
  25. }
  26. }
  27. override func awakeFromNib() {
  28. super.awakeFromNib()
  29. thumbnailImageView.layer.cornerRadius = 3
  30. thumbnailImageView.clipsToBounds = true
  31. NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
  32. themeDidChange()
  33. }
  34. @objc fileprivate func themeDidChange() {
  35. backgroundColor = PresentationTheme.current.colors.background
  36. titleLabel.textColor = PresentationTheme.current.colors.cellTextColor
  37. timeLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  38. sizeLabel.textColor = PresentationTheme.current.colors.cellTextColor
  39. }
  40. func update(media: VLCMLMedia) {
  41. titleLabel.text = media.title
  42. timeLabel.text = media.mediaDuration()
  43. sizeLabel.text = media.formatSize()
  44. if media.isThumbnailGenerated() {
  45. thumbnailImageView.image = UIImage(contentsOfFile: media.thumbnail.absoluteString)
  46. }
  47. }
  48. var isChecked: Bool = false {
  49. didSet {
  50. checkboxImageView.image = isChecked ? UIImage(named: "checkboxEmpty") : UIImage(named: "checkboxSelected")
  51. }
  52. }
  53. override func prepareForReuse() {
  54. super.prepareForReuse()
  55. titleLabel.text = ""
  56. timeLabel.text = ""
  57. sizeLabel.text = ""
  58. thumbnailImageView.image = nil
  59. }
  60. }