|
@@ -33,73 +33,13 @@ class LibrarySearchDataSource: NSObject {
|
|
|
searchData.removeAll()
|
|
|
let lowercaseSearchString = searchString.lowercased()
|
|
|
model.anyfiles.forEach {
|
|
|
- if let media = $0 as? VLCMLMedia {
|
|
|
- if media.contains(lowercaseSearchString) { searchData.append($0) }
|
|
|
- } else if let album = $0 as? VLCMLAlbum {
|
|
|
- if album.contains(lowercaseSearchString) { searchData.append($0) }
|
|
|
- } else if let genre = $0 as? VLCMLGenre {
|
|
|
- if genre.contains(lowercaseSearchString) { searchData.append($0) }
|
|
|
- } else if let playlist = $0 as? VLCMLPlaylist {
|
|
|
- if playlist.contains(lowercaseSearchString) { searchData.append($0) }
|
|
|
- } else if let artist = $0 as? VLCMLArtist {
|
|
|
- if artist.contains(lowercaseSearchString) { searchData.append($0) }
|
|
|
- } else if let albumtrack = $0 as? VLCMLAlbumTrack {
|
|
|
- if albumtrack.contains(lowercaseSearchString) { searchData.append($0) }
|
|
|
- } else {
|
|
|
- assertionFailure("unhandled type")
|
|
|
+ guard let searchableFile = $0 as? SearchableMLModel else {
|
|
|
+ assertionFailure("LibrarySearchDataSource: Unhandled type")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if searchableFile.contains(lowercaseSearchString) {
|
|
|
+ searchData.append($0)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-extension VLCMLObject {
|
|
|
- func contains(_ searchString: String) -> Bool {
|
|
|
- return false
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension VLCMLMedia {
|
|
|
- func contains(_ searchString: String) -> Bool {
|
|
|
- return title.lowercased().contains(searchString)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension VLCMLAlbum {
|
|
|
- func contains(_ searchString: String) -> Bool {
|
|
|
- var matches = false
|
|
|
- matches = matches || title.lowercased().contains(searchString)
|
|
|
- matches = matches || String(releaseYear()).lowercased().contains(searchString)
|
|
|
- matches = matches || shortSummary.lowercased().contains(searchString)
|
|
|
- matches = matches || albumArtist?.contains(searchString) ?? false
|
|
|
- matches = matches || tracks?.filter({ $0.contains(searchString)}).isEmpty == false
|
|
|
- return matches
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension VLCMLGenre {
|
|
|
- func contains(_ searchString: String) -> Bool {
|
|
|
- return name.lowercased().contains(searchString)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension VLCMLPlaylist {
|
|
|
- func contains(_ searchString: String) -> Bool {
|
|
|
- return name.lowercased().contains(searchString)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension VLCMLArtist {
|
|
|
- func contains(_ searchString: String) -> Bool {
|
|
|
- return name.lowercased().contains(searchString)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension VLCMLAlbumTrack {
|
|
|
- func contains(_ searchString: String) -> Bool {
|
|
|
- var matches = false
|
|
|
- matches = matches || artist?.contains(searchString) ?? false
|
|
|
- matches = matches || genre?.contains(searchString) ?? false
|
|
|
- matches = matches || album?.contains(searchString) ?? false
|
|
|
- return matches
|
|
|
- }
|
|
|
-}
|