Przeglądaj źródła

GenreModel: Use MediaCollectionViewCell

Soomin Lee 6 lat temu
rodzic
commit
e35eaa78cf

+ 1 - 1
SharedSources/MediaLibraryModel/GenreModel.swift

@@ -18,7 +18,7 @@ class GenreModel: MLBaseModel {
 
     var files = [VLCMLGenre]()
 
-    var cellType: BaseCollectionViewCell.Type { return GenreCollectionViewCell.self }
+    var cellType: BaseCollectionViewCell.Type { return MediaCollectionViewCell.self }
 
     var medialibrary: MediaLibraryService
 

+ 0 - 59
Sources/MediaCategoryCells/GenreCollectionViewCell.swift

@@ -1,59 +0,0 @@
-/*****************************************************************************
- * GenreCollectionViewCell.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 GenreCollectionViewCell: BaseCollectionViewCell {
-
-    @IBOutlet weak var thumbnailView: UIImageView!
-    @IBOutlet weak var titleLabel: UILabel!
-    @IBOutlet weak var numberOfTracksLabel: UILabel!
-
-    override var media: VLCMLObject? {
-        didSet {
-            guard let genre = media as? VLCMLGenre else {
-                fatalError("needs to be of Type VLCMLGenre")
-            }
-            update(genre:genre)
-        }
-    }
-
-    override func awakeFromNib() {
-        super.awakeFromNib()
-        NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
-        themeDidChange()
-        thumbnailView.layer.masksToBounds = true
-        thumbnailView.layer.cornerRadius = thumbnailView.frame.size.width / 2.0
-    }
-
-    @objc fileprivate func themeDidChange() {
-        backgroundColor = PresentationTheme.current.colors.background
-        titleLabel.textColor = PresentationTheme.current.colors.cellTextColor
-        numberOfTracksLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
-    }
-
-    func update(genre: VLCMLGenre) {
-        titleLabel.text = genre.name
-        numberOfTracksLabel.text = genre.numberOfTracksString()
-    }
-
-    override class func cellSizeForWidth(_ width: CGFloat) -> CGSize {
-        return CGSize(width: width, height: 50)
-    }
-
-    override func prepareForReuse() {
-        super.prepareForReuse()
-        titleLabel.text = ""
-        numberOfTracksLabel.text = ""
-        thumbnailView.image = nil
-    }
-}

+ 0 - 64
Sources/MediaCategoryCells/GenreCollectionViewCell.xib

@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" 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="14460.20"/>
-        <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="0xl-vS-wk4" customClass="GenreCollectionViewCell" customModule="VLC" customModuleProvider="target">
-            <rect key="frame" x="0.0" y="0.0" width="261" height="50"/>
-            <autoresizingMask key="autoresizingMask" flexibleMaxX="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="261" height="50"/>
-                <autoresizingMask key="autoresizingMask"/>
-                <subviews>
-                    <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="CQh-8k-37l">
-                        <rect key="frame" x="5" y="5" width="40" height="40"/>
-                        <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
-                        <constraints>
-                            <constraint firstAttribute="width" secondItem="CQh-8k-37l" secondAttribute="height" multiplier="1:1" id="A8I-aR-qlG"/>
-                        </constraints>
-                    </imageView>
-                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vOa-BW-3T8" userLabel="Title">
-                        <rect key="frame" x="53" y="2" width="208" height="21"/>
-                        <fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
-                        <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="ar1-X1-nOK" userLabel="Number of Tracks">
-                        <rect key="frame" x="53" y="27" width="208" height="16"/>
-                        <fontDescription key="fontDescription" type="system" weight="semibold" pointSize="13"/>
-                        <nil key="textColor"/>
-                        <nil key="highlightedColor"/>
-                    </label>
-                </subviews>
-            </view>
-            <constraints>
-                <constraint firstItem="ar1-X1-nOK" firstAttribute="leading" secondItem="vOa-BW-3T8" secondAttribute="leading" id="9hc-FQ-2Dn"/>
-                <constraint firstItem="vOa-BW-3T8" firstAttribute="leading" secondItem="CQh-8k-37l" secondAttribute="trailing" constant="8" id="CB9-eT-nmE"/>
-                <constraint firstItem="CQh-8k-37l" firstAttribute="top" secondItem="dse-0i-1qC" secondAttribute="top" constant="5" id="SHZ-2V-BGx"/>
-                <constraint firstItem="ar1-X1-nOK" firstAttribute="trailing" secondItem="vOa-BW-3T8" secondAttribute="trailing" id="TSA-1j-hPM"/>
-                <constraint firstItem="vOa-BW-3T8" firstAttribute="trailing" secondItem="dse-0i-1qC" secondAttribute="trailing" id="VxZ-fz-dbR"/>
-                <constraint firstItem="CQh-8k-37l" firstAttribute="bottom" secondItem="dse-0i-1qC" secondAttribute="bottom" constant="-5" id="WJ4-tu-Two"/>
-                <constraint firstItem="CQh-8k-37l" firstAttribute="leading" secondItem="dse-0i-1qC" secondAttribute="leading" constant="5" id="bei-Sv-jah"/>
-                <constraint firstItem="ar1-X1-nOK" firstAttribute="top" secondItem="CQh-8k-37l" secondAttribute="centerY" constant="2" id="r9I-0d-NWF"/>
-                <constraint firstItem="vOa-BW-3T8" firstAttribute="bottom" secondItem="CQh-8k-37l" secondAttribute="centerY" constant="-2" id="ySU-ZH-Wie"/>
-            </constraints>
-            <viewLayoutGuide key="safeArea" id="dse-0i-1qC"/>
-            <size key="customSize" width="261" height="94"/>
-            <connections>
-                <outlet property="numberOfTracksLabel" destination="ar1-X1-nOK" id="H4P-mO-G89"/>
-                <outlet property="thumbnailView" destination="CQh-8k-37l" id="qIb-cG-K0G"/>
-                <outlet property="titleLabel" destination="vOa-BW-3T8" id="twv-gj-cWR"/>
-            </connections>
-            <point key="canvasLocation" x="628" y="110.64467766116942"/>
-        </collectionViewCell>
-    </objects>
-</document>

+ 15 - 0
Sources/MediaCategoryCells/MediaCollectionViewCell.swift

@@ -31,6 +31,8 @@ class MediaCollectionViewCell: BaseCollectionViewCell {
                 update(movie:movie)
             } else if let playlist = media as? VLCMLPlaylist {
                 update(playlist: playlist)
+            } else if let genre = media as? VLCMLGenre {
+                update(genre: genre)
             } else {
                 fatalError("needs to be of Type VLCMLMedia or VLCMLAlbum")
             }
@@ -90,6 +92,19 @@ class MediaCollectionViewCell: BaseCollectionViewCell {
         thumbnailView.image = UIImage(contentsOfFile: playlist.artworkMrl())
     }
 
+    func update(genre: VLCMLGenre) {
+        newLabel.isHidden = true
+        titleLabel.text = genre.name
+
+        for track in genre.tracks() ?? [] {
+            if track.isThumbnailGenerated() {
+                thumbnailView.image = UIImage(contentsOfFile: track.thumbnail.path)
+                break
+            }
+        }
+        descriptionLabel.text = genre.numberOfTracksString()
+    }
+
     override class func cellSizeForWidth(_ width: CGFloat) -> CGSize {
         let numberOfCells: CGFloat
         if width <= DeviceWidth.iPhonePortrait.rawValue {

+ 0 - 8
VLC.xcodeproj/project.pbxproj

@@ -61,8 +61,6 @@
 		41B93C081A53853B00102E8B /* VLCCloudServiceCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41B93C071A53853B00102E8B /* VLCCloudServiceCell.xib */; };
 		41CD695C1A29D72600E60BCE /* VLCBoxController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41CD69591A29D72600E60BCE /* VLCBoxController.m */; };
 		41CD695D1A29D72600E60BCE /* VLCBoxTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41CD695B1A29D72600E60BCE /* VLCBoxTableViewController.m */; };
-		41CF03E821D117D100B449E0 /* GenreCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41CF03E721D117D100B449E0 /* GenreCollectionViewCell.swift */; };
-		41CF03EA21D1181100B449E0 /* GenreCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41CF03E921D1181100B449E0 /* GenreCollectionViewCell.xib */; };
 		41D7DD0520C1853E00AD94F6 /* ButtonBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41D7DD0420C1853E00AD94F6 /* ButtonBarView.swift */; };
 		41D7DD2120C1FC2D00AD94F6 /* VLCLabelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41D7DD2020C1FC2D00AD94F6 /* VLCLabelCell.xib */; };
 		41D7DD2720C3060300AD94F6 /* PagerStripViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41D7DD2620C3060300AD94F6 /* PagerStripViewController.swift */; };
@@ -538,8 +536,6 @@
 		41CD69591A29D72600E60BCE /* VLCBoxController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCBoxController.m; path = Sources/VLCBoxController.m; sourceTree = SOURCE_ROOT; };
 		41CD695A1A29D72600E60BCE /* VLCBoxTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCBoxTableViewController.h; path = Sources/VLCBoxTableViewController.h; sourceTree = SOURCE_ROOT; };
 		41CD695B1A29D72600E60BCE /* VLCBoxTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCBoxTableViewController.m; path = Sources/VLCBoxTableViewController.m; sourceTree = SOURCE_ROOT; };
-		41CF03E721D117D100B449E0 /* GenreCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenreCollectionViewCell.swift; sourceTree = "<group>"; };
-		41CF03E921D1181100B449E0 /* GenreCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GenreCollectionViewCell.xib; sourceTree = "<group>"; };
 		41D7DD0420C1853E00AD94F6 /* ButtonBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ButtonBarView.swift; path = Sources/ButtonBarView.swift; sourceTree = "<group>"; };
 		41D7DD2020C1FC2D00AD94F6 /* VLCLabelCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VLCLabelCell.xib; path = Resources/VLCLabelCell.xib; sourceTree = "<group>"; };
 		41D7DD2620C3060300AD94F6 /* PagerStripViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PagerStripViewController.swift; path = Sources/PagerStripViewController.swift; sourceTree = "<group>"; };
@@ -1157,8 +1153,6 @@
 				41EC28E82136DE46004BCF0F /* MovieCollectionViewCell.xib */,
 				41884A4F214BE0D800D2C6B4 /* MediaCollectionViewCell.swift */,
 				41884A4D214BE0C800D2C6B4 /* MediaCollectionViewCell.xib */,
-				41CF03E721D117D100B449E0 /* GenreCollectionViewCell.swift */,
-				41CF03E921D1181100B449E0 /* GenreCollectionViewCell.xib */,
 			);
 			name = MediaCategoryCells;
 			path = Sources/MediaCategoryCells;
@@ -2587,7 +2581,6 @@
 				417CDA241A48D1F300D9ACE7 /* VLCCloudServicesTableViewController.xib in Resources */,
 				7D9870671A3E03D5009CF27D /* papasscode_failed_bg@2x.png in Resources */,
 				41884A4E214BE0C800D2C6B4 /* MediaCollectionViewCell.xib in Resources */,
-				41CF03EA21D1181100B449E0 /* GenreCollectionViewCell.xib in Resources */,
 				7DDFF4251BDFD23300913BD1 /* VLCCone512x512.png in Resources */,
 				7DF04F4F1961F2B8004A5429 /* web-open-fixed.png in Resources */,
 				7DBBF19A183AB4300009A339 /* VLCCloudStorageTableViewCell~ipad.xib in Resources */,
@@ -2971,7 +2964,6 @@
 				DD3EFF4D1BDEBCE500B68579 /* VLCNetworkServerBrowserPlex.m in Sources */,
 				8D437154205808FF00F36458 /* ActionSheet.swift in Sources */,
 				DDF908E41CFCD97400108B70 /* VLCNetworkLoginDataSourceProtocol.m in Sources */,
-				41CF03E821D117D100B449E0 /* GenreCollectionViewCell.swift in Sources */,
 				8D66A47320AC61B900FA5B92 /* MediaLibraryService.swift in Sources */,
 				7D378492183A98BF009EE944 /* VLCExternalDisplayController.m in Sources */,
 				8DE1888C210B459000A091D2 /* ShowEpisodeModel.swift in Sources */,