Commit 54bb618c authored by Soomin Lee's avatar Soomin Lee

MediaLibraryBaseModel: Use callback to update view

parent 961aacab
......@@ -12,9 +12,9 @@
class AlbumModel: MediaLibraryBaseModel {
typealias MLType = VLCMLAlbum
var files = [VLCMLAlbum]()
var updateView: (() -> Void)?
var view: MediaLibraryModelView?
var files = [VLCMLAlbum]()
var indicatorName: String = NSLocalizedString("ALBUMS", comment: "")
......@@ -36,6 +36,6 @@ class AlbumModel: MediaLibraryBaseModel {
extension AlbumModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddAlbum album: [VLCMLAlbum]) {
album.forEach({ append($0) })
view?.dataChanged()
updateView?()
}
}
......@@ -12,9 +12,9 @@
class ArtistModel: MediaLibraryBaseModel {
typealias MLType = VLCMLArtist
var files = [VLCMLArtist]()
var updateView: (() -> Void)?
var view: MediaLibraryModelView?
var files = [VLCMLArtist]()
var indicatorName: String = NSLocalizedString("ARTISTS", comment: "")
......@@ -34,6 +34,6 @@ class ArtistModel: MediaLibraryBaseModel {
extension ArtistModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddArtist artist: [VLCMLArtist]) {
artist.forEach({ append($0) })
view?.dataChanged()
updateView?()
}
}
......@@ -12,9 +12,9 @@
class AudioModel: MediaLibraryBaseModel {
typealias MLType = VLCMLMedia
var files = [VLCMLMedia]()
var updateView: (() -> Void)?
var view: MediaLibraryModelView?
var files = [VLCMLMedia]()
var indicatorName: String = NSLocalizedString("SONGS", comment: "")
......@@ -36,6 +36,6 @@ class AudioModel: MediaLibraryBaseModel {
extension AudioModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddAudio audio: [VLCMLMedia]) {
audio.forEach({ append($0) })
view?.dataChanged()
updateView?()
}
}
......@@ -12,9 +12,9 @@
class GenreModel: MediaLibraryBaseModel {
typealias MLType = VLCMLGenre
var files = [VLCMLGenre]()
var updateView: (() -> Void)?
var view: MediaLibraryModelView?
var files = [VLCMLGenre]()
var indicatorName: String = NSLocalizedString("GENRE", comment: "")
......@@ -36,6 +36,6 @@ class GenreModel: MediaLibraryBaseModel {
extension GenreModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddGenre genre: [VLCMLGenre]) {
genre.forEach({ append($0) })
view?.dataChanged()
updateView?()
}
}
......@@ -19,7 +19,8 @@ protocol MediaLibraryBaseModel: class {
init(medialibrary: VLCMediaLibraryManager)
var files: [MLType] { get set }
var view: MediaLibraryModelView? { get set }
var updateView: (() -> Void)? { get set }
var indicatorName: String { get }
......
......@@ -12,6 +12,8 @@
class ShowEpisodeModel: MediaLibraryBaseModel {
typealias MLType = VLCMLMedia
var updateView: (() -> Void)?
var files = [VLCMLMedia]()
var view: MediaLibraryModelView?
......@@ -33,6 +35,6 @@ class ShowEpisodeModel: MediaLibraryBaseModel {
extension ShowEpisodeModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddShowEpisode showEpisode: [VLCMLMedia]) {
showEpisode.forEach({ append($0) })
view?.dataChanged()
updateView?()
}
}
......@@ -12,9 +12,9 @@
class VideoModel: MediaLibraryBaseModel {
typealias MLType = VLCMLMedia
var files = [VLCMLMedia]()
var updateView: (() -> Void)?
var view: MediaLibraryModelView?
var files = [VLCMLMedia]()
var indicatorName: String = NSLocalizedString("MOVIES", comment: "")
......@@ -33,6 +33,6 @@ class VideoModel: MediaLibraryBaseModel {
extension VideoModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddVideo video: [VLCMLMedia]) {
video.forEach({ append($0) })
view?.dataChanged()
updateView?()
}
}
......@@ -14,6 +14,9 @@ class VLCMovieCategoryViewController: VLCMediaCategoryViewController<VLCMLMedia,
init(_ services: Services) {
let model = VideoModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
category.updateView = { [weak self] in
self?.reloadData()
}
}
}
......@@ -21,6 +24,9 @@ class VLCShowEpisodeCategoryViewController: VLCMediaCategoryViewController<MLSho
init(_ services: Services) {
let model = ShowEpisodeModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
category.updateView = { [weak self] in
self?.reloadData()
}
}
}
......@@ -28,6 +34,9 @@ class VLCVideoPlaylistCategoryViewController: VLCMediaCategoryViewController<MLL
init(_ services: Services) {
let model = VideoModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
category.updateView = { [weak self] in
self?.reloadData()
}
}
}
......@@ -35,6 +44,9 @@ class VLCTrackCategoryViewController: VLCMediaCategoryViewController<VLCMLMedia,
init(_ services: Services) {
let model = AudioModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
category.updateView = { [weak self] in
self?.reloadData()
}
}
}
......@@ -42,6 +54,9 @@ class VLCGenreCategoryViewController: VLCMediaCategoryViewController<String, Gen
init(_ services: Services) {
let model = GenreModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
category.updateView = { [weak self] in
self?.reloadData()
}
}
}
......@@ -49,6 +64,9 @@ class VLCArtistCategoryViewController: VLCMediaCategoryViewController<String, Ar
init(_ services: Services) {
let model = ArtistModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
category.updateView = { [weak self] in
self?.reloadData()
}
}
}
......@@ -56,6 +74,9 @@ class VLCAlbumCategoryViewController: VLCMediaCategoryViewController<MLAlbum, Al
init(_ services: Services) {
let model = AlbumModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
category.updateView = { [weak self] in
self?.reloadData()
}
}
}
......@@ -63,5 +84,8 @@ class VLCAudioPlaylistCategoryViewController: VLCMediaCategoryViewController<MLL
init(_ services: Services) {
let model = VideoModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
category.updateView = { [weak self] in
self?.reloadData()
}
}
}
......@@ -42,7 +42,6 @@ class VLCMediaCategoryViewController<T, ModelType: MediaLibraryBaseModel>: UICol
self.category = category
super.init(collectionViewLayout: UICollectionViewFlowLayout())
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
category.view = self
}
override var preferredStatusBarStyle: UIStatusBarStyle {
......
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