Browse Source

Artist: add cell to represent artist

Carola Nitz 6 years ago
parent
commit
3e618f2133

+ 1 - 1
SharedSources/MediaLibraryModel/ArtistModel.swift

@@ -16,7 +16,7 @@ class ArtistModel: MLBaseModel {
 
     var files = [VLCMLArtist]()
 
-    var cellType: BaseCollectionViewCell.Type { return MovieCollectionViewCell.self }
+    var cellType: BaseCollectionViewCell.Type { return ArtistCollectionViewCell.self }
 
     var medialibrary: VLCMediaLibraryManager
 

+ 68 - 0
Sources/MediaCategoryCells/ArtistCollectionViewCell.swift

@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * ArtistCollectionViewCell.swift
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2019 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 ArtistCollectionViewCell: BaseCollectionViewCell {
+
+    @IBOutlet weak var thumbnailView: UIImageView!
+    @IBOutlet weak var titleLabel: UILabel!
+    override class var cellPadding: CGFloat {
+        return 5.0
+    }
+
+    override var media: VLCMLObject? {
+        didSet {
+            guard let artist = media as? VLCMLArtist else {
+                fatalError("needs to be of Type VLCMLArtist")
+            }
+            update(artist:artist)
+        }
+    }
+
+    override func awakeFromNib() {
+        super.awakeFromNib()
+        NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
+        themeDidChange()
+        thumbnailView.layer.cornerRadius = thumbnailView.frame.size.width / 2.0
+    }
+
+    @objc fileprivate func themeDidChange() {
+        backgroundColor = PresentationTheme.current.colors.background
+        titleLabel?.textColor = PresentationTheme.current.colors.cellTextColor
+    }
+
+    func update(artist: VLCMLArtist) {
+        titleLabel.text = artist.name
+//        if artist.isThumbnailGenerated() {
+//            thumbnailView.image = UIImage(contentsOfFile: artist.thumbnail.absoluteString)
+//        }
+    }
+
+    override class func cellSizeForWidth(_ width: CGFloat) -> CGSize {
+        let numberOfCells: CGFloat = round(width / 320)
+
+        // 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)
+
+        return CGSize(width: cellWidth, height: 80)
+    }
+
+    override func prepareForReuse() {
+        super.prepareForReuse()
+        titleLabel.text = ""
+        thumbnailView.image = nil
+    }
+}

+ 58 - 0
Sources/MediaCategoryCells/ArtistCollectionViewCell.xib

@@ -0,0 +1,58 @@
+<?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="fI9-1M-oXc" userLabel="Artist Collection View Cell" customClass="ArtistCollectionViewCell" customModule="VLC" customModuleProvider="target">
+            <rect key="frame" x="0.0" y="0.0" width="480" height="80"/>
+            <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="480" height="80"/>
+                <autoresizingMask key="autoresizingMask"/>
+                <subviews>
+                    <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" alignment="center" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="Nb7-g2-bfe">
+                        <rect key="frame" x="0.0" y="0.0" width="480" height="80"/>
+                        <subviews>
+                            <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Pzk-JI-feR" userLabel="Thumbnail">
+                                <rect key="frame" x="0.0" y="12" width="56" height="56"/>
+                                <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="calibratedWhite"/>
+                                <constraints>
+                                    <constraint firstAttribute="width" constant="56" id="J0U-RA-XMJ"/>
+                                    <constraint firstAttribute="width" secondItem="Pzk-JI-feR" secondAttribute="height" multiplier="1:1" id="rER-R7-FEy"/>
+                                </constraints>
+                            </imageView>
+                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Yqb-DZ-IMW" userLabel="Titlelabel">
+                                <rect key="frame" x="64" y="30" width="416" height="20.5"/>
+                                <fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
+                                <nil key="textColor"/>
+                                <nil key="highlightedColor"/>
+                            </label>
+                        </subviews>
+                    </stackView>
+                </subviews>
+            </view>
+            <constraints>
+                <constraint firstItem="Nb7-g2-bfe" firstAttribute="leading" secondItem="35G-Qy-Qgr" secondAttribute="leading" id="5ci-DO-npT"/>
+                <constraint firstItem="35G-Qy-Qgr" firstAttribute="bottom" secondItem="Nb7-g2-bfe" secondAttribute="bottom" id="EYI-Xl-HI5"/>
+                <constraint firstItem="35G-Qy-Qgr" firstAttribute="trailing" secondItem="Nb7-g2-bfe" secondAttribute="trailing" id="NBx-qQ-d6o"/>
+                <constraint firstItem="Nb7-g2-bfe" firstAttribute="top" secondItem="35G-Qy-Qgr" secondAttribute="top" id="SYo-ET-B2N"/>
+            </constraints>
+            <viewLayoutGuide key="safeArea" id="35G-Qy-Qgr"/>
+            <size key="customSize" width="480" height="213"/>
+            <connections>
+                <outlet property="thumbnailView" destination="Pzk-JI-feR" id="EIq-7H-jM2"/>
+                <outlet property="titleLabel" destination="Yqb-DZ-IMW" id="OMw-8z-eHS"/>
+            </connections>
+            <point key="canvasLocation" x="110" y="-53.5"/>
+        </collectionViewCell>
+    </objects>
+</document>

+ 8 - 0
VLC.xcodeproj/project.pbxproj

@@ -16,6 +16,8 @@
 		41251ED01FD0CF7900099110 /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41251ECE1FD0CF7900099110 /* AppCoordinator.swift */; };
 		41273A3C1A955C4100A2EF77 /* VLCMigrationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */; };
 		41273A3D1A955C4100A2EF77 /* VLCMigrationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */; };
+		41364DF621FF5B7D00AC22B3 /* ArtistCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41364DF521FF5B7D00AC22B3 /* ArtistCollectionViewCell.swift */; };
+		41364DF821FF5D2600AC22B3 /* ArtistCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41364DF721FF5D2600AC22B3 /* ArtistCollectionViewCell.xib */; };
 		413EC987201A329D00BF412F /* SortOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 413EC986201A329D00BF412F /* SortOption.swift */; };
 		413EC98B201B4F2C00BF412F /* PresentationTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 413EC98A201B4F2B00BF412F /* PresentationTheme.swift */; };
 		414327A521B6E55700B061F6 /* PlaybackSpeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 414327A421B6E55700B061F6 /* PlaybackSpeedView.swift */; };
@@ -421,6 +423,8 @@
 		41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCMigrationViewController.m; path = Sources/VLCMigrationViewController.m; sourceTree = SOURCE_ROOT; };
 		41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VLCMigrationViewController.xib; path = Sources/VLCMigrationViewController.xib; sourceTree = SOURCE_ROOT; };
 		412BE7521FC4947400ACCC42 /* VLCMediaSubcategory+VLCDragAndDrop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "VLCMediaSubcategory+VLCDragAndDrop.swift"; path = "Sources/VLCMediaSubcategory+VLCDragAndDrop.swift"; sourceTree = SOURCE_ROOT; };
+		41364DF521FF5B7D00AC22B3 /* ArtistCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistCollectionViewCell.swift; sourceTree = "<group>"; };
+		41364DF721FF5D2600AC22B3 /* ArtistCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ArtistCollectionViewCell.xib; sourceTree = "<group>"; };
 		413EC986201A329D00BF412F /* SortOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SortOption.swift; path = Sources/Coordinators/SortOption.swift; sourceTree = SOURCE_ROOT; };
 		413EC98A201B4F2B00BF412F /* PresentationTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationTheme.swift; sourceTree = "<group>"; };
 		414327A421B6E55700B061F6 /* PlaybackSpeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PlaybackSpeedView.swift; path = Sources/PlaybackSpeedView.swift; sourceTree = "<group>"; };
@@ -1138,6 +1142,8 @@
 				41884A4D214BE0C800D2C6B4 /* AudioCollectionViewCell.xib */,
 				41CF03E721D117D100B449E0 /* GenreCollectionViewCell.swift */,
 				41CF03E921D1181100B449E0 /* GenreCollectionViewCell.xib */,
+				41364DF521FF5B7D00AC22B3 /* ArtistCollectionViewCell.swift */,
+				41364DF721FF5D2600AC22B3 /* ArtistCollectionViewCell.xib */,
 			);
 			name = MediaCategoryCells;
 			path = Sources/MediaCategoryCells;
@@ -2530,6 +2536,7 @@
 				7DF04F4F1961F2B8004A5429 /* web-open-fixed.png in Resources */,
 				7DBBF19A183AB4300009A339 /* VLCCloudStorageTableViewCell~ipad.xib in Resources */,
 				7D1516421868D7E0004B18F3 /* VLCFirstStepsFifthPageViewController.xib in Resources */,
+				41364DF821FF5D2600AC22B3 /* ArtistCollectionViewCell.xib in Resources */,
 				41B4DA3E21400E8E000BA27D /* MediaEditCell.xib in Resources */,
 				7D9870641A3E03D5009CF27D /* papasscode_background.png in Resources */,
 				7D0117F1187F4BA400C5671C /* VLCFirstStepsFirstPageViewController~ipad.xib in Resources */,
@@ -2870,6 +2877,7 @@
 				8DF9669D2113317E00D0FCD6 /* VLCEditToolbar.swift in Sources */,
 				416443862048419E00CAC646 /* DeviceMotion.swift in Sources */,
 				7D9289751877459B009108FD /* VLCFirstStepsThirdPageViewController.m in Sources */,
+				41364DF621FF5B7D00AC22B3 /* ArtistCollectionViewCell.swift in Sources */,
 				7D95610B1AF3E9E800779745 /* VLCMiniPlaybackView.m in Sources */,
 				DD3EFF451BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserManualConnect.m in Sources */,
 				8DF966B121188BDB00D0FCD6 /* VLCEditController.swift in Sources */,