Browse Source

MediaCollectionModel: Refactor thumbnails into one single function

Edgar Fouillet 5 years ago
parent
commit
fcea33fdda

+ 0 - 15
SharedSources/MediaLibraryModel/AlbumModel.swift

@@ -130,21 +130,6 @@ extension VLCMLAlbum {
         return String(format: tracksString, trackCount)
     }
 
-    @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
-    }
-
     func albumName() -> String {
         return isUnknownAlbum() ? NSLocalizedString("UNKNOWN_ALBUM", comment: "") : title
     }

+ 0 - 15
SharedSources/MediaLibraryModel/ArtistModel.swift

@@ -119,21 +119,6 @@ extension VLCMLArtist {
         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
-    }
-
     func artistName() -> String {
         if identifier() == UnknownArtistID {
             return NSLocalizedString("UNKNOWN_ARTIST", comment: "")

+ 0 - 13
SharedSources/MediaLibraryModel/GenreModel.swift

@@ -100,19 +100,6 @@ 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
-    }
-
     func accessibilityText() -> String? {
         return name + " " + numberOfTracksString()
     }

+ 19 - 0
SharedSources/MediaLibraryModel/MediaLibraryBaseModel.swift

@@ -112,4 +112,23 @@ extension MediaCollectionModel {
                desc: Bool = false) -> [VLCMLMedia]? {
         return files(with: criteria, desc: desc)
     }
+
+    func thumbnail() -> UIImage? {
+        var image: UIImage? = nil
+        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
+            if self is VLCMLVideoGroup {
+                image = isDarktheme ? UIImage(named: "movie-placeholder-dark") : UIImage(named: "movie-placeholder-white")
+            } else {
+                image = isDarktheme ? UIImage(named: "album-placeholder-dark") : UIImage(named: "album-placeholder-white")
+            }
+        }
+        return image
+    }
 }

+ 0 - 15
SharedSources/MediaLibraryModel/PlaylistModel.swift

@@ -125,21 +125,6 @@ extension VLCMLPlaylist {
         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
-    }
-
     func accessibilityText() -> String? {
         return name + " " + numberOfTracksString()
     }

+ 0 - 15
SharedSources/MediaLibraryModel/VideoGroupViewModel.swift

@@ -119,21 +119,6 @@ extension VLCMLVideoGroup {
         return String(format: tracksString, mediaCount)
     }
 
-    @objc func thumbnail() -> UIImage? {
-        var image: UIImage?
-
-        for media in files() ?? [] where media.isThumbnailGenerated() {
-            image = UIImage(contentsOfFile: media.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
-    }
-
     func accessibilityText() -> String? {
         return name() + " " + numberOfTracksString()
     }