123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /*****************************************************************************
- * VLCMediaViewEditCell.swift
- *
- * Copyright © 2018 VLC authors and VideoLAN
- * Copyright © 2018 Videolabs
- *
- * Authors: Soomin Lee <bubu@mikan.io>
- * Carola Nitz <nitz.carola@googlemail.com>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- class MediaEditCell: BaseCollectionViewCell {
- static let height: CGFloat = 88
- @IBOutlet weak var checkboxImageView: UIImageView!
- @IBOutlet weak var thumbnailImageView: UIImageView!
- @IBOutlet weak var titleLabel: UILabel!
- @IBOutlet weak var timeLabel: UILabel!
- @IBOutlet weak var sizeLabel: UILabel!
- @IBOutlet weak var VideoAspectRatio: NSLayoutConstraint!
- @IBOutlet weak var AudioAspectRatio: NSLayoutConstraint!
- override var media: VLCMLObject? {
- didSet {
- if let movie = media as? VLCMLMedia, movie.type() == .video {
- updateForMovie(movie: movie)
- } else if let artist = media as? VLCMLArtist {
- updateForArtist(artist: artist)
- } else if let album = media as? VLCMLAlbum {
- updateForAlbum(album: album)
- } else if let genre = media as? VLCMLGenre {
- updateForGenre(genre: genre)
- } else if let playlist = media as? VLCMLPlaylist {
- updateForPlaylist(playlist: playlist)
- } else if let audio = media as? VLCMLMedia, audio.type() == .audio {
- updateForAudio(audio: audio)
- } else {
- fatalError("needs to be of a supported Type")
- }
- }
- }
- override func awakeFromNib() {
- super.awakeFromNib()
- thumbnailImageView.clipsToBounds = true
- NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
- themeDidChange()
- }
- @objc fileprivate func themeDidChange() {
- backgroundColor = PresentationTheme.current.colors.background
- titleLabel.textColor = PresentationTheme.current.colors.cellTextColor
- timeLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
- sizeLabel.textColor = PresentationTheme.current.colors.cellTextColor
- }
- func updateForMovie(movie: VLCMLMedia) {
- thumbnailImageView.layer.cornerRadius = 3
- AudioAspectRatio.isActive = false
- VideoAspectRatio.isActive = true
- titleLabel.text = movie.title
- timeLabel.text = movie.mediaDuration()
- sizeLabel.text = movie.formatSize()
- thumbnailImageView.image = movie.thumbnailImage()
- }
- func updateForAudio(audio: VLCMLMedia) {
- titleLabel.text = audio.title
- timeLabel.text = audio.mediaDuration()
- sizeLabel.text = audio.formatSize()
- thumbnailImageView.image = audio.thumbnailImage()
- thumbnailImageView.layer.masksToBounds = true
- thumbnailImageView.layer.cornerRadius = thumbnailImageView.frame.size.height / 2
- }
- func updateForArtist(artist: VLCMLArtist) {
- titleLabel.text = artist.name
- timeLabel.text = artist.numberOfTracksString()
- thumbnailImageView.layer.masksToBounds = true
- thumbnailImageView.layer.cornerRadius = thumbnailImageView.frame.size.height / 2
- thumbnailImageView.image = artist.thumbnail()
- }
- func updateForAlbum(album: VLCMLAlbum) {
- titleLabel.text = album.title
- timeLabel.text = album.albumArtist?.name ?? NSLocalizedString("UNKNOWN_ARTIST", comment: "")
- sizeLabel.text = album.numberOfTracksString()
- thumbnailImageView.image = album.thumbnail()
- }
- func updateForGenre(genre: VLCMLGenre) {
- titleLabel.text = genre.name
- timeLabel.text = genre.numberOfTracksString()
- thumbnailImageView.layer.masksToBounds = true
- thumbnailImageView.layer.cornerRadius = thumbnailImageView.frame.size.height / 2
- thumbnailImageView.image = genre.thumbnail()
- }
- func updateForPlaylist(playlist: VLCMLPlaylist) {
- thumbnailImageView.layer.cornerRadius = 3
- AudioAspectRatio.isActive = false
- VideoAspectRatio.isActive = true
- titleLabel.text = playlist.name
- timeLabel.text = playlist.numberOfTracksString()
- thumbnailImageView.image = playlist.thumbnail()
- }
- var isChecked: Bool = false {
- didSet {
- checkboxImageView.image = isChecked ? UIImage(named: "checkboxSelected") : UIImage(named: "checkboxEmpty")
- }
- }
- override class func cellSizeForWidth(_ width: CGFloat) -> CGSize {
- let numberOfCells: CGFloat
- if width <= DeviceWidth.iPhonePortrait.rawValue {
- numberOfCells = 1
- } else if width <= DeviceWidth.iPhoneLandscape.rawValue {
- numberOfCells = 2
- } else {
- numberOfCells = 3
- }
- // We have the number of cells and we always have numberofCells + 1 interItemPadding spaces.
- //
- // edgePadding-interItemPadding-[Cell]-interItemPadding-[Cell]-interItemPadding-edgePadding
- //
- let overallWidth = width - (2 * edgePadding)
- let overallCellWidthWithoutPadding = overallWidth - (numberOfCells + 1) * interItemPadding
- let cellWidth = floor(overallCellWidthWithoutPadding / numberOfCells)
- return CGSize(width: cellWidth, height: height)
- }
- override func prepareForReuse() {
- super.prepareForReuse()
- titleLabel.text = ""
- timeLabel.text = ""
- sizeLabel.text = ""
- thumbnailImageView.image = nil
- isChecked = false
- thumbnailImageView.layer.cornerRadius = 0
- AudioAspectRatio.isActive = true
- VideoAspectRatio.isActive = false
- }
- }
|