Commit 2afc73a8 authored by Soomin Lee's avatar Soomin Lee

MLModel: Add delete method

parent e918072d
......@@ -29,6 +29,10 @@ class AlbumModel: MLBaseModel {
func append(_ item: VLCMLAlbum) {
files.append(item)
}
func delete(_ items: [VLCMLObject]) {
preconditionFailure("AlbumModel: Cannot delete album")
}
}
extension AlbumModel: MediaLibraryObserver {
......
......@@ -29,6 +29,10 @@ class ArtistModel: MLBaseModel {
func append(_ item: VLCMLArtist) {
files.append(item)
}
func delete(_ items: [VLCMLObject]) {
preconditionFailure("ArtistModel: Cannot delete artist")
}
}
extension ArtistModel: MediaLibraryObserver {
......
......@@ -29,6 +29,18 @@ class AudioModel: MLBaseModel {
func append(_ item: VLCMLMedia) {
files.append(item)
}
func delete(_ items: [VLCMLObject]) {
do {
for case let media as VLCMLMedia in items {
try FileManager.default.removeItem(atPath: media.mainFile().mrl.path)
}
medialibrary.reload()
}
catch let error as NSError {
assertionFailure("VideoModel: Delete failed: \(error.localizedDescription)")
}
}
}
// MARK: - Sort
......
......@@ -29,6 +29,10 @@ class GenreModel: MLBaseModel {
func append(_ item: VLCMLGenre) {
files.append(item)
}
func delete(_ items: [VLCMLObject]) {
preconditionFailure("GenreModel: Cannot delete genre")
}
}
extension GenreModel: MediaLibraryObserver {
......
......@@ -20,6 +20,7 @@ protocol MediaLibraryBaseModel {
var indicatorName: String { get }
func append(_ item: VLCMLObject)
func delete(_ items: [VLCMLObject])
func sort(by criteria: VLCMLSortingCriteria)
}
......@@ -37,6 +38,8 @@ protocol MLBaseModel: MediaLibraryBaseModel {
var indicatorName: String { get }
func append(_ item: MLType)
// FIXME: Ideally items should be MLType but Swift isn't happy so it will always fail
func delete(_ items: [VLCMLObject])
func sort(by criteria: VLCMLSortingCriteria)
}
......@@ -49,6 +52,10 @@ extension MLBaseModel {
fatalError()
}
func delete(_ items: [VLCMLObject]) {
fatalError()
}
func sort(by criteria: VLCMLSortingCriteria) {
fatalError()
}
......
......@@ -28,6 +28,10 @@ class ShowEpisodeModel: MLBaseModel {
func append(_ item: VLCMLMedia) {
files.append(item)
}
func delete(_ items: [VLCMLObject]) {
preconditionFailure("ShowEpisodeModel: Cannot delete showEpisode")
}
}
extension ShowEpisodeModel: MediaLibraryObserver {
......
......@@ -29,6 +29,18 @@ class VideoModel: MLBaseModel {
func append(_ item: VLCMLMedia) {
files.append(item)
}
func delete(_ items: [VLCMLObject]) {
do {
for case let media as VLCMLMedia in items {
try FileManager.default.removeItem(atPath: media.mainFile().mrl.path)
}
medialibrary.reload()
}
catch let error as NSError {
assertionFailure("VideoModel: Delete failed: \(error.localizedDescription)")
}
}
}
// MARK: - Sort
......
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