Commit d5225e9b authored by Carola Nitz's avatar Carola Nitz

MovieCollectionViewCell: Implement the new design for movie files

- This removes the old playlistTableviewcell and Collectionviewcell
- it puts in place the architecture for further cells by adding a baseCollectionViewCell
parent 1b0a21b8
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="14092" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="ipad9_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14081.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="VLCPlaylistCollectionViewCell" id="2" customClass="VLCPlaylistCollectionViewCell">
<rect key="frame" x="0.0" y="0.0" width="341" height="190"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="341" height="190"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" translatesAutoresizingMaskIntoConstraints="NO" id="31">
<rect key="frame" x="0.0" y="0.0" width="341" height="190"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</imageView>
<imageView hidden="YES" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="top" image="folderIcon.png" translatesAutoresizingMaskIntoConstraints="NO" id="0uT-W6-UMC">
<rect key="frame" x="0.0" y="60" width="341" height="130"/>
<constraints>
<constraint firstAttribute="height" constant="130" id="Xse-Zt-V2T"/>
</constraints>
</imageView>
<imageView opaque="NO" clearsContextBeforeDrawing="NO" userInteractionEnabled="NO" contentMode="scaleToFill" image="gradient-cell-ios7" translatesAutoresizingMaskIntoConstraints="NO" id="Gzk-gj-0jk">
<rect key="frame" x="0.0" y="0.0" width="341" height="190"/>
</imageView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" misplaced="YES" text="Title" textAlignment="justified" lineBreakMode="tailTruncation" baselineAdjustment="none" adjustsLetterSpacingToFitWidth="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4XD-oC-pqG">
<rect key="frame" x="10" y="141" width="331" height="22"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="18"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<size key="shadowOffset" width="0.0" height="0.0"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="New" textAlignment="justified" lineBreakMode="wordWrap" baselineAdjustment="none" minimumFontSize="9" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ftR-Og-FOs">
<rect key="frame" x="304" y="8" width="29" height="16"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<size key="shadowOffset" width="0.0" height="0.0"/>
</label>
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="checkboxEmpty.png" translatesAutoresizingMaskIntoConstraints="NO" id="pl6-iw-2ZI">
<rect key="frame" x="6" y="6" width="25" height="25"/>
</imageView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" misplaced="YES" text="Subtitle — Subtitle" textAlignment="natural" lineBreakMode="wordWrap" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="jdp-lJ-hIF">
<rect key="frame" x="10" y="166" width="114" height="16"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="12"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<size key="shadowOffset" width="0.0" height="0.0"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Meta Data" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lP6-D2-Oef">
<rect key="frame" x="141.5" y="8" width="58.5" height="14.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="1" green="1" blue="1" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</view>
<constraints>
<constraint firstAttribute="bottom" secondItem="31" secondAttribute="bottom" id="2Dv-fj-XSY"/>
<constraint firstItem="4XD-oC-pqG" firstAttribute="trailing" secondItem="31" secondAttribute="trailing" id="3ru-uR-dxu"/>
<constraint firstItem="Gzk-gj-0jk" firstAttribute="leading" secondItem="2" secondAttribute="leading" id="4VB-hN-L6X"/>
<constraint firstItem="jdp-lJ-hIF" firstAttribute="leading" secondItem="2" secondAttribute="leadingMargin" constant="2" id="65e-1U-ucq"/>
<constraint firstItem="0uT-W6-UMC" firstAttribute="leading" secondItem="2" secondAttribute="leading" id="6Bc-Mo-Zvt"/>
<constraint firstAttribute="bottom" secondItem="jdp-lJ-hIF" secondAttribute="bottom" constant="8" id="AVR-YF-5FR"/>
<constraint firstItem="ftR-Og-FOs" firstAttribute="top" secondItem="2" secondAttribute="top" constant="8" id="Cf0-yy-7iB"/>
<constraint firstAttribute="trailing" secondItem="0uT-W6-UMC" secondAttribute="trailing" id="I1e-9b-1Eu"/>
<constraint firstItem="4XD-oC-pqG" firstAttribute="leading" secondItem="2" secondAttribute="leadingMargin" constant="2" id="Myr-sC-Y6O"/>
<constraint firstItem="0uT-W6-UMC" firstAttribute="top" secondItem="31" secondAttribute="bottom" constant="-130" id="Owc-pg-OJY"/>
<constraint firstItem="pl6-iw-2ZI" firstAttribute="top" secondItem="2" secondAttribute="top" constant="6" id="SKc-13-c0F"/>
<constraint firstItem="ftR-Og-FOs" firstAttribute="height" secondItem="jdp-lJ-hIF" secondAttribute="height" id="UwZ-3F-Sbj"/>
<constraint firstItem="Gzk-gj-0jk" firstAttribute="top" secondItem="2" secondAttribute="top" id="XMJ-wS-Zg4"/>
<constraint firstItem="31" firstAttribute="top" secondItem="2" secondAttribute="top" id="YMD-tj-91G"/>
<constraint firstAttribute="trailing" secondItem="ftR-Og-FOs" secondAttribute="trailing" constant="8" id="bcZ-dH-pSC"/>
<constraint firstAttribute="bottom" secondItem="Gzk-gj-0jk" secondAttribute="bottom" id="e0A-1e-hof"/>
<constraint firstItem="lP6-D2-Oef" firstAttribute="top" secondItem="2" secondAttribute="top" constant="8" id="gcu-no-yiW"/>
<constraint firstItem="lP6-D2-Oef" firstAttribute="centerX" secondItem="Gzk-gj-0jk" secondAttribute="centerX" id="hF6-wk-HUE"/>
<constraint firstItem="pl6-iw-2ZI" firstAttribute="leading" secondItem="2" secondAttribute="leading" constant="6" id="lWY-9H-Xrv"/>
<constraint firstAttribute="trailing" secondItem="31" secondAttribute="trailing" id="mmM-A8-uNu"/>
<constraint firstItem="jdp-lJ-hIF" firstAttribute="top" secondItem="4XD-oC-pqG" secondAttribute="bottom" constant="3" id="odO-K3-Eql"/>
<constraint firstItem="31" firstAttribute="leading" secondItem="2" secondAttribute="leading" id="tP4-CX-bVc"/>
<constraint firstAttribute="trailing" secondItem="Gzk-gj-0jk" secondAttribute="trailing" id="uZk-Aw-Ubw"/>
</constraints>
<size key="customSize" width="298" height="167"/>
<connections>
<outlet property="folderIconView" destination="0uT-W6-UMC" id="coZ-4M-nCp"/>
<outlet property="isSelectedView" destination="pl6-iw-2ZI" id="1sX-gh-yiU"/>
<outlet property="mediaIsUnreadView" destination="ftR-Og-FOs" id="5aH-vE-E37"/>
<outlet property="metaDataLabel" destination="lP6-D2-Oef" id="OBz-fP-Wk1"/>
<outlet property="subtitleLabel" destination="jdp-lJ-hIF" id="YUa-G7-CMl"/>
<outlet property="thumbnailView" destination="31" id="46"/>
<outlet property="titleLabel" destination="4XD-oC-pqG" id="Te1-JA-An0"/>
</connections>
</collectionViewCell>
</objects>
<resources>
<image name="checkboxEmpty.png" width="25" height="25"/>
<image name="folderIcon.png" width="221" height="205"/>
<image name="gradient-cell-ios7" width="2" height="190"/>
</resources>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14092" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14081.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" indentationWidth="10" reuseIdentifier="VLCPlaylistTableViewCell" rowHeight="191" id="3" customClass="VLCPlaylistTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="90"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="3" id="pEL-yt-P8r">
<rect key="frame" x="0.0" y="0.0" width="320" height="89.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" translatesAutoresizingMaskIntoConstraints="NO" id="4">
<rect key="frame" x="0.0" y="0.0" width="320" height="89"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</imageView>
<imageView hidden="YES" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="top" image="folderIcon.png" translatesAutoresizingMaskIntoConstraints="NO" id="5iA-hI-rrr">
<rect key="frame" x="0.0" y="35" width="320" height="54"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="gradient-cell-ios7" translatesAutoresizingMaskIntoConstraints="NO" id="22">
<rect key="frame" x="0.0" y="0.0" width="320" height="89"/>
</imageView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="none" adjustsLetterSpacingToFitWidth="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6">
<rect key="frame" x="8" y="40" width="312" height="18"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="15"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<size key="shadowOffset" width="0.0" height="0.0"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="New" textAlignment="right" lineBreakMode="wordWrap" baselineAdjustment="none" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="sYw-l2-Tmv">
<rect key="frame" x="286" y="66" width="26" height="15"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<size key="shadowOffset" width="0.0" height="0.0"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Subtitle — Subtitle" lineBreakMode="wordWrap" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="7">
<rect key="frame" x="8" y="66" width="106" height="15"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<size key="shadowOffset" width="0.0" height="0.0"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Meta Data" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3xi-uj-aAV">
<rect key="frame" x="131.5" y="8" width="58.5" height="14.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="1" green="1" blue="1" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="5iA-hI-rrr" firstAttribute="top" secondItem="pEL-yt-P8r" secondAttribute="top" constant="35" id="0e6-eB-gIO"/>
<constraint firstItem="sYw-l2-Tmv" firstAttribute="height" secondItem="7" secondAttribute="height" id="1N5-73-wMe"/>
<constraint firstAttribute="trailing" secondItem="22" secondAttribute="trailing" id="1Zz-cK-59T"/>
<constraint firstItem="6" firstAttribute="leading" secondItem="pEL-yt-P8r" secondAttribute="leading" constant="8" id="B58-rD-stL"/>
<constraint firstItem="4" firstAttribute="leading" secondItem="pEL-yt-P8r" secondAttribute="leading" id="BWt-6F-Z6H"/>
<constraint firstItem="7" firstAttribute="top" secondItem="6" secondAttribute="bottom" constant="8" id="FDZ-lE-uBQ"/>
<constraint firstItem="3xi-uj-aAV" firstAttribute="top" secondItem="pEL-yt-P8r" secondAttribute="top" constant="8" id="G7M-XR-ut3"/>
<constraint firstItem="6" firstAttribute="trailing" secondItem="4" secondAttribute="trailing" id="GgF-Jk-5oG"/>
<constraint firstAttribute="bottom" secondItem="22" secondAttribute="bottom" id="JC6-Q6-E9V"/>
<constraint firstAttribute="bottom" secondItem="sYw-l2-Tmv" secondAttribute="bottom" constant="8" id="MpI-5C-JLG"/>
<constraint firstAttribute="trailing" secondItem="5iA-hI-rrr" secondAttribute="trailing" id="PfR-Cm-d7h"/>
<constraint firstAttribute="trailing" secondItem="4" secondAttribute="trailing" id="Q12-b6-BKB"/>
<constraint firstAttribute="bottom" secondItem="5iA-hI-rrr" secondAttribute="bottom" id="Thz-vE-rDq"/>
<constraint firstAttribute="bottom" secondItem="7" secondAttribute="bottom" constant="8" id="V2A-54-5Em"/>
<constraint firstItem="22" firstAttribute="top" secondItem="pEL-yt-P8r" secondAttribute="top" id="VLS-dT-bzc"/>
<constraint firstItem="5iA-hI-rrr" firstAttribute="leading" secondItem="pEL-yt-P8r" secondAttribute="leading" id="VNu-Ix-mHw"/>
<constraint firstItem="22" firstAttribute="leading" secondItem="pEL-yt-P8r" secondAttribute="leading" id="XbD-ch-L0p"/>
<constraint firstItem="3xi-uj-aAV" firstAttribute="centerX" secondItem="22" secondAttribute="centerX" id="Y3s-4z-kaM"/>
<constraint firstAttribute="trailing" secondItem="sYw-l2-Tmv" secondAttribute="trailing" constant="8" id="Zcw-z4-u4F"/>
<constraint firstItem="7" firstAttribute="leading" secondItem="pEL-yt-P8r" secondAttribute="leading" constant="8" id="faR-g7-XYt"/>
<constraint firstAttribute="bottom" secondItem="4" secondAttribute="bottom" id="izG-dY-vNl"/>
<constraint firstItem="4" firstAttribute="top" secondItem="pEL-yt-P8r" secondAttribute="top" id="j8t-Ng-xOy"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" red="0.11999999731779099" green="0.11999999731779099" blue="0.11999999731779099" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outlet property="folderIconView" destination="5iA-hI-rrr" id="K2w-2u-dEl"/>
<outlet property="mediaIsUnreadView" destination="sYw-l2-Tmv" id="us6-sJ-NVp"/>
<outlet property="metaDataLabel" destination="3xi-uj-aAV" id="BXL-7W-XC9"/>
<outlet property="subtitleLabel" destination="7" id="8"/>
<outlet property="thumbnailView" destination="4" id="9"/>
<outlet property="titleLabel" destination="6" id="10"/>
</connections>
</tableViewCell>
</objects>
<resources>
<image name="folderIcon.png" width="221" height="205"/>
<image name="gradient-cell-ios7" width="2" height="92"/>
</resources>
</document>
......@@ -18,6 +18,7 @@ protocol MediaLibraryBaseModel {
var updateView: (() -> Void)? { get set }
var indicatorName: String { get }
var cellType: BaseCollectionViewCell.Type { get }
func append(_ item: VLCMLObject)
func delete(_ items: [VLCMLObject])
......@@ -44,6 +45,10 @@ protocol MLBaseModel: MediaLibraryBaseModel {
}
extension MLBaseModel {
var cellType: BaseCollectionViewCell.Type {
return MovieCollectionViewCell.self
}
var anyfiles: [VLCMLObject] {
return files
}
......
......@@ -95,7 +95,7 @@ extension VLCMLMedia {
}
extension VLCMLMedia {
@objc func formatDuration() -> String {
@objc func mediaDuration() -> String {
return String(format: "%@", VLCTime(int: Int32(duration())))
}
......@@ -103,4 +103,17 @@ extension VLCMLMedia {
return ByteCountFormatter.string(fromByteCount: Int64(mainFile().size()),
countStyle: .file)
}
func mediaProgress() -> Float {
guard let string = metadata(of: .progress).str as NSString? else {
return 0.0
}
return string.floatValue
}
func isNew() -> Bool {
let integer = metadata(of: .seen).integer()
return integer == 0
}
}
/*****************************************************************************
* 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!
override var media: VLCMLObject? {
didSet {
guard let movie = media as? VLCMLMedia else {
fatalError("needs to be of Type VLCMLMovie")
}
update(movie:movie)
}
}
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()
}
override func prepareForReuse() {
super.prepareForReuse()
titleLabel.text = ""
descriptionLabel.text = ""
thumbnailView.image = nil
progressView.isHidden = true
newLabel.isHidden = true
}
}
/*****************************************************************************
* BaseCollectionViewCell.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 BaseCollectionViewCell: UICollectionViewCell {
static var defaultReuseIdentifier: String {
return NSStringFromClass(self)
}
class var nibName: String {
return String(describing:self)
}
var media: VLCMLObject?
}
......@@ -92,8 +92,8 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
}
func setupCollectionView() {
let playlistnib = UINib(nibName: "VLCPlaylistCollectionViewCell", bundle: nil)
collectionView?.register(playlistnib, forCellWithReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier())
let cellNib = UINib(nibName: category.cellType.nibName, bundle: nil)
collectionView?.register(cellNib, forCellWithReuseIdentifier: category.cellType.defaultReuseIdentifier)
collectionView?.register(VLCMediaViewEditCell.self, forCellWithReuseIdentifier: VLCMediaViewEditCell.identifier)
collectionView?.backgroundColor = PresentationTheme.current.colors.background
collectionView?.alwaysBounceVertical = true
......@@ -190,24 +190,23 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let playlistCell = collectionView.dequeueReusableCell(withReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier(), for: indexPath) as? VLCPlaylistCollectionViewCell {
if let mediaObject = category.anyfiles[indexPath.row] as? NSManagedObject {
playlistCell.mediaObject = mediaObject
}
guard let mediaCell = collectionView.dequeueReusableCell(withReuseIdentifier:category.cellType.defaultReuseIdentifier, for: indexPath) as? BaseCollectionViewCell else {
assertionFailure("you forgot to register the cell or the cell is not a subclass of BaseCollectionViewCell")
return UICollectionViewCell()
}
if let media = category.anyfiles[indexPath.row] as? VLCMLMedia {
playlistCell.media = (media.mainFile() != nil) ? media : nil
}
return playlistCell
guard let media = category.anyfiles[indexPath.row] as? VLCMLMedia else {
assertionFailure("The contained file in the category doesn't conform to VLCMLMedia")
return mediaCell
}
return UICollectionViewCell()
assert(media.mainFile() != nil, "The mainfile is nil")
mediaCell.media = media.mainFile() != nil ? media : nil
return mediaCell
}
// MARK: - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let mediaObject = category.anyfiles[indexPath.row] as? NSManagedObject {
play(mediaObject: mediaObject)
} else if let media = category.anyfiles[indexPath.row] as? VLCMLMedia {
if let media = category.anyfiles[indexPath.row] as? VLCMLMedia {
play(media: media)
}
}
......@@ -215,7 +214,7 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
// MARK: - UICollectionViewDelegateFlowLayout
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let numberOfCells: CGFloat = collectionView.traitCollection.horizontalSizeClass == .regular ? 3.0 : 2.0
let numberOfCells: CGFloat = round(collectionView.frame.size.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-
......@@ -224,7 +223,8 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
var cellWidth = collectionView.bounds.size.width / numberOfCells
cellWidth = cellWidth - ceil(((numberOfCells + 1) * cellPadding) / numberOfCells)
return CGSize(width: cellWidth, height: cellWidth * aspectRatio)
// 3*20 for the labels + 24 for 3*8 which is the padding
return CGSize(width: cellWidth, height: cellWidth * aspectRatio + 3*20+24)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
......
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="YyZ-zI-cD7" customClass="MovieCollectionViewCell" customModule="VLC" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="309" height="230"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
<rect key="frame" x="0.0" y="0.0" width="309" height="230"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="iWM-y0-SUe">
<rect key="frame" x="0.0" y="0.0" width="309" height="230"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="jmi-G0-XOo" userLabel="Thumbnail">
<rect key="frame" x="0.0" y="0.0" width="309" height="193"/>
<color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" secondItem="jmi-G0-XOo" secondAttribute="height" multiplier="16:10" id="Oml-o7-Dfl"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4zQ-Mf-dw7" userLabel="Titlelabel">
<rect key="frame" x="0.0" y="201" width="37.5" height="7.5"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="VeB-L1-KVk">
<rect key="frame" x="0.0" y="216.5" width="63" height="13.5"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="Cgk-mu-ntx">
<rect key="frame" x="0.0" y="0.0" width="63" height="13.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="new" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Aby-eq-q1j" userLabel="NewLabel">
<rect key="frame" x="0.0" y="0.0" width="23" height="13.5"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="11"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oac-dS-Qcd" userLabel="descriptionLabel">
<rect key="frame" x="31" y="0.0" width="32" height="13.5"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
</stackView>
</subviews>
</stackView>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="X8l-k0-1oc">
<rect key="frame" x="0.0" y="191" width="309" height="2"/>
<color key="tintColor" red="0.9552378654" green="0.65840983580000001" blue="0.28695866590000002" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
</progressView>
</subviews>
</view>
<constraints>
<constraint firstItem="iWM-y0-SUe" firstAttribute="bottom" relation="lessThanOrEqual" secondItem="YyZ-zI-cD7" secondAttribute="bottom" id="3VI-xW-KQ4"/>
<constraint firstItem="iWM-y0-SUe" firstAttribute="leading" secondItem="YyZ-zI-cD7" secondAttribute="leading" id="43e-Na-uN0"/>
<constraint firstItem="VeB-L1-KVk" firstAttribute="leading" secondItem="BvH-0B-sVS" secondAttribute="leading" id="8tP-cl-aIe"/>
<constraint firstItem="4zQ-Mf-dw7" firstAttribute="leading" secondItem="BvH-0B-sVS" secondAttribute="leading" id="Ijd-61-ouV"/>
<constraint firstAttribute="trailing" secondItem="iWM-y0-SUe" secondAttribute="trailing" id="PrI-Yq-B9j"/>
<constraint firstItem="iWM-y0-SUe" firstAttribute="leading" secondItem="X8l-k0-1oc" secondAttribute="leading" id="Rq2-SS-aA2"/>
<constraint firstItem="X8l-k0-1oc" firstAttribute="leading" secondItem="jmi-G0-XOo" secondAttribute="leading" id="WvI-Ra-xlu"/>
<constraint firstItem="iWM-y0-SUe" firstAttribute="top" secondItem="YyZ-zI-cD7" secondAttribute="top" id="Y4b-8y-MOG"/>
<constraint firstItem="X8l-k0-1oc" firstAttribute="trailing" secondItem="jmi-G0-XOo" secondAttribute="trailing" id="d8L-w5-ba5"/>
<constraint firstItem="X8l-k0-1oc" firstAttribute="bottom" secondItem="jmi-G0-XOo" secondAttribute="bottom" id="dWh-bB-nfd"/>
<constraint firstItem="jmi-G0-XOo" firstAttribute="width" secondItem="YyZ-zI-cD7" secondAttribute="width" id="t8h-GJ-GvI"/>
</constraints>
<viewLayoutGuide key="safeArea" id="BvH-0B-sVS"/>
<size key="customSize" width="309" height="230"/>
<connections>
<outlet property="descriptionLabel" destination="oac-dS-Qcd" id="1iJ-b6-gC6"/>
<outlet property="newLabel" destination="Aby-eq-q1j" id="4rD-oo-gdq"/>
<outlet property="progressView" destination="X8l-k0-1oc" id="mf9-zf-3ya"/>
<outlet property="thumbnailView" destination="jmi-G0-XOo" id="gMW-XK-9MV"/>
<outlet property="titleLabel" destination="4zQ-Mf-dw7" id="iGP-8x-anz"/>
</connections>
<point key="canvasLocation" x="-99.5" y="136"/>
</collectionViewCell>
</objects>
</document>
......@@ -196,7 +196,7 @@ extension VLCEditController: UICollectionViewDataSource {
for: indexPath) as? VLCMediaViewEditCell {
if let media = category.anyfiles[indexPath.row] as? VLCMLMedia {
cell.titleLabel.text = media.title
cell.subInfoLabel.text = media.formatDuration()
cell.subInfoLabel.text = media.mediaDuration()
cell.sizeLabel.text = media.formatSize()
}
return cell
......
......@@ -11,8 +11,6 @@
*****************************************************************************/
#import "VLCLibrarySearchDisplayDataSource.h"
#import "VLCPlaylistTableViewCell.h"
#import "VLCPlaylistCollectionViewCell.h"
@interface VLCLibrarySearchDisplayDataSource() <UITableViewDataSource>
{
......@@ -38,25 +36,14 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:VLCPlaylistTableViewCell.cellIdentifier forIndexPath:indexPath];
NSInteger row = indexPath.row;
if (row < _searchData.count)
cell.mediaObject = _searchData[row];
return cell;
//needs to be updated as part of https://code.videolan.org/videolan/vlc-ios/issues/182
return [UITableViewCell new];
}
- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
VLCPlaylistCollectionViewCell *cell = (VLCPlaylistCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCPlaylistCollectionViewCell.cellIdentifier forIndexPath:indexPath];
NSInteger row = indexPath.row;
if (row < _searchData.count)
cell.mediaObject = _searchData[row];
return cell;
//needs to be updated as part of https://code.videolan.org/videolan/vlc-ios/issues/182
return [UICollectionViewCell new];
}
- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
......
/*****************************************************************************
* VLCPlaylistCollectionViewCell.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2013-2018 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
* Tamas Timar <ttimar.vlc # gmail.com>
* Gleb Pinigin <gpinigin # gmail.com>
* Carola Nitz <nitz.carola # gmail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <UIKit/UIKit.h>
#import "VLCLinearProgressIndicator.h"
@class VLCMLMedia;
@interface VLCPlaylistCollectionViewCell : UICollectionViewCell
@property (nonatomic, strong) IBOutlet UILabel *titleLabel;
@property (nonatomic, strong) IBOutlet UILabel *subtitleLabel;
@property (nonatomic, strong) IBOutlet UIImageView *thumbnailView;
@property (nonatomic, strong) IBOutlet VLCLinearProgressIndicator *progressView;
@property (nonatomic, strong) IBOutlet UIView *mediaIsUnreadView;
@property (nonatomic, strong) IBOutlet UIImageView *isSelectedView;
@property (nonatomic, strong) IBOutlet UIImageView *folderIconView;
@property (nonatomic, strong) IBOutlet UILabel *metaDataLabel;
@property (nonatomic, retain) NSManagedObject *mediaObject;
@property (nonatomic, retain) VLCMLMedia *media;
@property (nonatomic, weak) UICollectionView *collectionView;
@property (readonly) BOOL showsMetaData;
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
- (void)selectionUpdate;
- (void)showMetadata:(BOOL)showMeta;
+ (NSString *)cellIdentifier;
@end
/*****************************************************************************
* VLCPlaylistCollectionViewCell.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2013-2018 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
* Tamas Timar <ttimar.vlc # gmail.com>
* Gleb Pinigin <gpinigin # gmail.com>
* Carola Nitz <nitz.carola # googlemail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCPlaylistCollectionViewCell.h"
#import "VLCThumbnailsCache.h"
#import "NSString+SupportedMedia.h"
#import "VLC-Swift.h"
@interface VLCPlaylistCollectionViewCell ()
{
UIImage *_checkboxEmptyImage;
UIImage *_checkboxImage;
BOOL _editing;
}
@end
@implementation VLCPlaylistCollectionViewCell
- (void)dealloc
{
[self _removeObserver];
}
- (void)awakeFromNib
{
_checkboxEmptyImage = [UIImage imageNamed:@"checkboxEmpty"];
_checkboxImage = [UIImage imageNamed:@"checkbox"];
self.metaDataLabel.hidden = YES;
[super awakeFromNib];
}
+ (NSString *)cellIdentifier
{
return @"VLCPlaylistCollectionViewCell";
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
_editing = editing;
self.isSelectedView.hidden = !_editing;
[self shake];
[self selectionUpdate];
[self _updatedDisplayedInformationForKeyPath:@"editing"];
}
- (void)selectionUpdate
{
if (self.selected)
self.isSelectedView.image = _checkboxImage;