1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /*****************************************************************************
- * MovieCollectionViewCell.swift
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2018 VideoLAN. All rights reserved.
- * $Id$
- *
- * Authors: Carola Nitz <nitz.carola # googlemail.com>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- import Foundation
- class MovieCollectionViewCell: BaseCollectionViewCell {
- @IBOutlet weak var thumbnailView: UIImageView!
- @IBOutlet weak var titleLabel: UILabel!
- @IBOutlet weak var newLabel: UILabel!
- @IBOutlet weak var descriptionLabel: UILabel!
- @IBOutlet weak var progressView: UIProgressView!
- @IBOutlet weak var collectionOverlay: UIView!
- @IBOutlet weak var numberOfTracks: UILabel!
- override class var cellPadding: CGFloat {
- return 5.0
- }
- override var media: VLCMLObject? {
- didSet {
- if let movie = media as? VLCMLMedia {
- update(movie:movie)
- } else if let playlist = media as? VLCMLPlaylist {
- update(playlist:playlist)
- } else {
- fatalError("wrong object")
- }
- }
- }
- override func awakeFromNib() {
- super.awakeFromNib()
- newLabel.text = NSLocalizedString("NEW", comment: "")
- newLabel.textColor = PresentationTheme.current.colors.orangeUI
- 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
- descriptionLabel?.textColor = PresentationTheme.current.colors.cellDetailTextColor
- }
- func update(movie: VLCMLMedia) {
- titleLabel.text = movie.title
- descriptionLabel.text = movie.mediaDuration()
- if movie.isThumbnailGenerated() {
- thumbnailView.image = UIImage(contentsOfFile: movie.thumbnail.absoluteString)
- }
- let progress = movie.mediaProgress()
- progressView.isHidden = progress == 0
- progressView.progress = progress
- newLabel.isHidden = !movie.isNew()
- }
- func update(playlist: VLCMLPlaylist) {
- collectionOverlay.isHidden = false
- numberOfTracks.text = String(playlist.media.count)
- titleLabel.text = playlist.name
- descriptionLabel.text = playlist.description()
- }
- override class func cellSizeForWidth(_ width: CGFloat) -> CGSize {
- let numberOfCells: CGFloat = round(width / 250)
- let aspectRatio: CGFloat = 10.0 / 16.0
- // We have the number of cells and we always have numberofCells + 1 padding spaces. -pad-[Cell]-pad-[Cell]-pad-
- // we then have the entire padding, we divide the entire padding by the number of Cells to know how much needs to be substracted from ech cell
- // since this might be an uneven number we ceil
- var cellWidth = width / numberOfCells
- cellWidth = cellWidth - ceil(((numberOfCells + 1) * cellPadding) / numberOfCells)
- // 3*20 for the labels + 24 for 3*8 which is the padding
- return CGSize(width: cellWidth, height: cellWidth * aspectRatio + 3*20+24)
- }
- override func prepareForReuse() {
- super.prepareForReuse()
- titleLabel.text = ""
- descriptionLabel.text = ""
- thumbnailView.image = nil
- progressView.isHidden = true
- newLabel.isHidden = true
- collectionOverlay.isHidden = true
- numberOfTracks.text = ""
- }
- }
|