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

MediaLibraryBaseModel: Use callback to update view

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