Commit 13abd78b authored by Carola Nitz's avatar Carola Nitz

MediaCollectionViewCell: Add placeholder images

(fixes #482 fixes #477)
parent 8c4a03a2
......@@ -355,3 +355,7 @@
// VLCNetworkLoginTVViewController
"NO_SAVING_DATA" = "Nothing found";
/* New strings */
"UNKNOWN_ARTIST" = "Unknown Artist";
"UNKNOWN_TITLE" = "Unknown Title";
......@@ -86,3 +86,19 @@ extension VLCMLAlbum: MediaCollectionModel {
return title
}
}
extension VLCMLAlbum {
@objc func thumbnail() -> UIImage? {
var image = UIImage(contentsOfFile: artworkMrl.path)
if image == nil {
for track in files() ?? [] where track.isThumbnailGenerated() {
image = UIImage(contentsOfFile: track.thumbnail.path)
break
}
}
if image == nil {
let isDarktheme = PresentationTheme.current == PresentationTheme.darkTheme
image = isDarktheme ? UIImage(named: "album-placeholder-dark") : UIImage(named: "album-placeholder-white")
}
return image
}
}
......@@ -93,4 +93,19 @@ extension VLCMLArtist {
let tracksString = tracks()?.count == 1 ? NSLocalizedString("TRACK", comment: "") : NSLocalizedString("TRACKS", comment: "")
return String(format: tracksString, tracks()?.count ?? 0)
}
@objc func thumbnail() -> UIImage? {
var image = UIImage(contentsOfFile: artworkMrl.path)
if image == nil {
for track in files() ?? [] where track.isThumbnailGenerated() {
image = UIImage(contentsOfFile: track.thumbnail.path)
break
}
}
if image == nil {
let isDarktheme = PresentationTheme.current == PresentationTheme.darkTheme
image = isDarktheme ? UIImage(named: "artist-placeholder-dark") : UIImage(named: "artist-placeholder-white")
}
return image
}
}
......@@ -84,6 +84,19 @@ extension VLCMLGenre {
}
return String(format: NSLocalizedString("TRACK", comment: ""), numberOftracks)
}
func thumbnail() -> UIImage? {
var image: UIImage? = nil
for track in tracks() ?? [] where track.isThumbnailGenerated() {
image = UIImage(contentsOfFile: track.thumbnail.path)
break
}
if image == nil {
let isDarktheme = PresentationTheme.current == PresentationTheme.darkTheme
image = isDarktheme ? UIImage(named: "song-placeholder-dark") : UIImage(named: "song-placeholder-white")
}
return image
}
}
extension VLCMLGenre: MediaCollectionModel {
......
......@@ -50,6 +50,20 @@ extension VLCMLMedia {
return ByteCountFormatter.string(fromByteCount: Int64(mainFile()?.size() ?? 0),
countStyle: .file)
}
@objc func thumbnailImage() -> UIImage? {
var image = UIImage(contentsOfFile: thumbnail.path)
if image == nil {
let isDarktheme = PresentationTheme.current == PresentationTheme.darkTheme
if subtype() == .albumTrack {
image = isDarktheme ? UIImage(named: "song-placeholder-dark") : UIImage(named: "song-placeholder-white")
} else {
image = isDarktheme ? UIImage(named: "movie-placeholder-dark") : UIImage(named: "movie-placeholder-white")
}
}
return image
}
}
// MARK: - CoreSpotlight
......
......@@ -101,6 +101,21 @@ extension VLCMLPlaylist {
let tracksString = mediaCount > 1 ? NSLocalizedString("TRACKS", comment: "") : NSLocalizedString("TRACK", comment: "")
return String(format: tracksString, mediaCount)
}
@objc func thumbnail() -> UIImage? {
var image = UIImage(contentsOfFile: artworkMrl())
if image == nil {
for track in files() ?? [] where track.isThumbnailGenerated() {
image = UIImage(contentsOfFile: track.thumbnail.path)
break
}
}
if image == nil {
let isDarktheme = PresentationTheme.current == PresentationTheme.darkTheme
image = isDarktheme ? UIImage(named: "movie-placeholder-dark") : UIImage(named: "movie-placeholder-white")
}
return image
}
}
extension VLCMLPlaylist: MediaCollectionModel {
......
......@@ -49,7 +49,8 @@
self.artist = media.albumTrack.artist.name;
self.trackNumber = @(media.albumTrack.trackNumber);
self.albumName = media.albumTrack.album.title;
self.artworkImage = [[UIImage alloc] initWithContentsOfFile:media.thumbnail.path];
self.artworkImage = [media thumbnailImage];
self.isAudioOnly = [media subtype] == VLCMLMediaSubtypeAlbumTrack;
} else { // We're streaming something
self.artworkImage = nil;
self.trackNumber = nil;
......
......@@ -57,23 +57,15 @@ class MediaCollectionViewCell: BaseCollectionViewCell {
thumbnailView.layer.masksToBounds = true
thumbnailView.layer.cornerRadius = thumbnailView.frame.size.width / 2.0
titleLabel.text = audiotrack.title
descriptionLabel.text = audiotrack.albumTrack?.artist?.name ?? ""
if audiotrack.isThumbnailGenerated() {
thumbnailView.image = UIImage(contentsOfFile: audiotrack.thumbnail.path)
}
descriptionLabel.text = audiotrack.albumTrack?.artist?.name ?? NSLocalizedString("UNKNOWN_ARTIST", comment: "")
newLabel.isHidden = !audiotrack.isNew
thumbnailView.image = audiotrack.thumbnailImage()
}
func update(album: VLCMLAlbum) {
titleLabel.text = album.title
descriptionLabel.text = album.albumArtist?.name ?? ""
thumbnailView.image = UIImage(contentsOfFile: album.artworkMrl.path)
if thumbnailView.image == nil {
for track in album.files() ?? [] where track.isThumbnailGenerated() {
thumbnailView.image = UIImage(contentsOfFile: track.thumbnail.path)
break
}
}
titleLabel.text = album.title != "" ? album.title : NSLocalizedString("UNKNOWN_TITLE", comment: "")
descriptionLabel.text = album.albumArtist?.name != "" ? album.albumArtist?.name : NSLocalizedString("UNKNOWN_ARTIST", comment: "")
thumbnailView.image = album.thumbnail()
}
func update(artist: VLCMLArtist) {
......@@ -81,13 +73,7 @@ class MediaCollectionViewCell: BaseCollectionViewCell {
thumbnailView.layer.cornerRadius = thumbnailView.frame.size.width / 2.0
titleLabel.text = artist.name
descriptionLabel.text = artist.numberOfTracksString()
thumbnailView.image = UIImage(contentsOfFile: artist.artworkMrl.path)
if thumbnailView.image == nil {
for track in artist.files() ?? [] where track.isThumbnailGenerated() {
thumbnailView.image = UIImage(contentsOfFile: track.thumbnail.path)
break
}
}
thumbnailView.image = artist.thumbnail()
}
func update(movie: VLCMLMedia) {
......@@ -103,23 +89,14 @@ class MediaCollectionViewCell: BaseCollectionViewCell {
newLabel.isHidden = true
titleLabel.text = playlist.name
descriptionLabel.text = playlist.numberOfTracksString()
thumbnailView.image = UIImage(contentsOfFile: playlist.artworkMrl())
if thumbnailView.image == nil {
for track in playlist.files() ?? [] where track.isThumbnailGenerated() {
thumbnailView.image = UIImage(contentsOfFile: track.thumbnail.path)
break
}
}
thumbnailView.image = playlist.thumbnail()
}
func update(genre: VLCMLGenre) {
newLabel.isHidden = true
titleLabel.text = genre.name
for track in genre.tracks() ?? [] where track.isThumbnailGenerated() {
thumbnailView.image = UIImage(contentsOfFile: track.thumbnail.path)
break
}
thumbnailView.image = genre.thumbnail()
descriptionLabel.text = genre.numberOfTracksString()
}
......
......@@ -57,9 +57,7 @@ class MovieCollectionViewCell: BaseCollectionViewCell {
func update(movie: VLCMLMedia) {
titleLabel.text = movie.title
descriptionLabel.text = movie.mediaDuration()
if movie.isThumbnailGenerated() {
thumbnailView.image = UIImage(contentsOfFile: movie.thumbnail.path)
}
thumbnailView.image = movie.thumbnailImage()
let progress = movie.progress
progressView.isHidden = progress == 0
progressView.progress = progress
......@@ -71,13 +69,7 @@ class MovieCollectionViewCell: BaseCollectionViewCell {
numberOfTracks.text = String(playlist.media?.count ?? 0)
titleLabel.text = playlist.name
descriptionLabel.text = playlist.numberOfTracksString()
thumbnailView.image = UIImage(contentsOfFile: playlist.artworkMrl())
if thumbnailView.image == nil {
for track in playlist.files() ?? [] where track.isThumbnailGenerated() {
thumbnailView.image = UIImage(contentsOfFile: track.thumbnail.path)
break
}
}
thumbnailView.image = playlist.thumbnail()
}
override class func cellSizeForWidth(_ width: CGFloat) -> CGSize {
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "Albumplaceholderdark.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Albumplaceholderdark@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Albumplaceholderdark@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Albumplaceholder.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Albumplaceholder@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Albumplaceholder@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "artistdark.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "artistdark@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "artistdark@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ArtistWhite.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ArtistWhite@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ArtistWhite@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "moviedark.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "moviedark@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "moviedark@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "moviewhite.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "moviewhite@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "moviewhite@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "songdark.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "songdark@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "songdark@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "songwhite.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "songwhite@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "songwhite@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment