Ver código fonte

SortModel: Facilitate init through array of criteria

Soomin Lee 6 anos atrás
pai
commit
ec11446e91

+ 1 - 4
SharedSources/MediaLibraryModel/AlbumModel.swift

@@ -12,10 +12,7 @@
 class AlbumModel: MLBaseModel {
     typealias MLType = VLCMLAlbum
 
-    var sortModel = SortModel(alpha: true,
-                              duration: true,
-                              releaseDate: true,
-                              trackNumber: true)
+    var sortModel = SortModel([.alpha, .duration, .releaseDate, .trackNumber])
 
     var updateView: (() -> Void)?
 

+ 1 - 1
SharedSources/MediaLibraryModel/ArtistModel.swift

@@ -12,7 +12,7 @@
 class ArtistModel: MLBaseModel {
     typealias MLType = VLCMLArtist
 
-    var sortModel = SortModel(alpha: true)
+    var sortModel = SortModel([.alpha])
 
     var updateView: (() -> Void)?
 

+ 1 - 3
SharedSources/MediaLibraryModel/AudioModel.swift

@@ -12,9 +12,7 @@
 class AudioModel: MediaModel {
     typealias MLType = VLCMLMedia
 
-    var sortModel = SortModel(alpha: true,
-                              duration: true,
-                              fileSize: true)
+    var sortModel = SortModel([.alpha, .duration, .fileSize])
 
     var updateView: (() -> Void)?
 

+ 1 - 1
SharedSources/MediaLibraryModel/GenreModel.swift

@@ -12,7 +12,7 @@
 class GenreModel: MLBaseModel {
     typealias MLType = VLCMLGenre
 
-    var sortModel = SortModel(alpha: true)
+    var sortModel = SortModel([.alpha])
 
     var updateView: (() -> Void)?
 

+ 1 - 2
SharedSources/MediaLibraryModel/PlaylistModel.swift

@@ -12,8 +12,7 @@
 class PlaylistModel: MLBaseModel {
     typealias MLType = VLCMLPlaylist
 
-    var sortModel = SortModel(alpha: true,
-                              duration: true)
+    var sortModel = SortModel([.alpha, .duration])
 
     var updateView: (() -> Void)?
 

+ 1 - 5
SharedSources/MediaLibraryModel/ShowEpisodeModel.swift

@@ -12,11 +12,7 @@
 class ShowEpisodeModel: MLBaseModel {
     typealias MLType = VLCMLMedia
 
-    var sortModel = SortModel(alpha: true,
-                              duration: true,
-                              insertionDate: true,
-                              releaseDate: true,
-                              fileSize: true)
+    var sortModel = SortModel([.alpha, .duration, .insertionDate, .releaseDate, .fileSize])
 
     var updateView: (() -> Void)?
 

+ 1 - 5
SharedSources/MediaLibraryModel/VideoModel.swift

@@ -12,11 +12,7 @@
 class VideoModel: MediaModel {
     typealias MLType = VLCMLMedia
 
-    var sortModel = SortModel(alpha: true,
-                              duration: true,
-                              insertionDate: true,
-                              releaseDate: true,
-                              fileSize: true)
+    var sortModel = SortModel([.alpha, .duration, .insertionDate, .releaseDate, .fileSize])
 
     var updateView: (() -> Void)?
 

+ 3 - 26
Sources/Coordinators/SortModel.swift

@@ -13,35 +13,12 @@
 struct SortModel {
     var currentSort: VLCMLSortingCriteria
     var desc: Bool
-    var sortingCriteria: [Bool]
-
-    init(alpha: Bool = true,
-         duration: Bool = false,
-         insertionDate: Bool = false,
-         lastModificationDate: Bool = false,
-         releaseDate: Bool = false,
-         fileSize: Bool = false,
-         artist: Bool = false,
-         playCount: Bool = false,
-         album: Bool = false,
-         filename: Bool = false,
-         trackNumber: Bool = false) {
+    var sortingCriteria: [VLCMLSortingCriteria]
 
+    init(_ criteria: [VLCMLSortingCriteria]) {
+        sortingCriteria = criteria
         currentSort = .default
         desc = false
-        // The first element of this array should always be VLCMLSortingCriteriaDefault
-        sortingCriteria = [false,
-                           alpha,
-                           duration,
-                           insertionDate,
-                           lastModificationDate,
-                           releaseDate,
-                           fileSize,
-                           artist,
-                           playCount,
-                           album,
-                           filename,
-                           trackNumber]
     }
 }