Commit 841e19c8 authored by Soomin Lee's avatar Soomin Lee

MediaLibraryBaseModel: Remove notification usage to views

parent 1163d8cb
......@@ -14,9 +14,9 @@ class AlbumModel: MediaLibraryBaseModel {
var files = [VLCMLAlbum]()
var indicatorName: String = NSLocalizedString("ALBUMS", comment: "")
var view: MediaLibraryModelView?
var notificaitonName: Notification.Name = .VLCAlbumsDidChangeNotification
var indicatorName: String = NSLocalizedString("ALBUMS", comment: "")
required init(medialibrary: VLCMediaLibraryManager) {
medialibrary.addObserver(self)
......@@ -36,6 +36,6 @@ class AlbumModel: MediaLibraryBaseModel {
extension AlbumModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddAlbum album: [VLCMLAlbum]) {
album.forEach({ append($0) })
NotificationCenter.default.post(name: notificaitonName, object: nil)
view?.dataChanged()
}
}
......@@ -14,9 +14,9 @@ class ArtistModel: MediaLibraryBaseModel {
var files = [VLCMLArtist]()
var indicatorName: String = NSLocalizedString("ARTISTS", comment: "")
var view: MediaLibraryModelView?
var notificaitonName: Notification.Name = .VLCArtistsDidChangeNotification
var indicatorName: String = NSLocalizedString("ARTISTS", comment: "")
required init(medialibrary: VLCMediaLibraryManager) {
medialibrary.addObserver(self)
......@@ -34,6 +34,6 @@ class ArtistModel: MediaLibraryBaseModel {
extension ArtistModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddArtist artist: [VLCMLArtist]) {
artist.forEach({ append($0) })
NotificationCenter.default.post(name: notificaitonName, object: nil)
view?.dataChanged()
}
}
......@@ -14,9 +14,9 @@ class AudioModel: MediaLibraryBaseModel {
var files = [VLCMLMedia]()
var indicatorName: String = NSLocalizedString("SONGS", comment: "")
var view: MediaLibraryModelView?
var notificaitonName: Notification.Name = .VLCAudioDidChangeNotification
var indicatorName: String = NSLocalizedString("SONGS", comment: "")
required init(medialibrary: VLCMediaLibraryManager) {
medialibrary.addObserver(self)
......@@ -36,6 +36,6 @@ class AudioModel: MediaLibraryBaseModel {
extension AudioModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddAudio audio: [VLCMLMedia]) {
audio.forEach({ append($0) })
NotificationCenter.default.post(name: notificaitonName, object: nil)
view?.dataChanged()
}
}
......@@ -22,18 +22,21 @@ extension Notification.Name {
static let VLCAudioDidChangeNotification = Notification.Name("AudioDidChangeNotfication")
}
protocol MediaLibraryBaseModel {
protocol MediaLibraryModelView {
func dataChanged()
}
protocol MediaLibraryBaseModel: class {
associatedtype MLType where MLType: VLCMLObject
init(medialibrary: VLCMediaLibraryManager)
var files: [MLType] { get set }
var view: MediaLibraryModelView? { get set }
var indicatorName: String { get }
var notificaitonName: Notification.Name { get }
// mutating will depend if we need to handle struc/enum
func append(_ item: MLType)
func isIncluded(_ item: MLType)
}
// protocol can be extended to have the "generic methods" that
// childs will share. No need an in-between class
......@@ -14,9 +14,9 @@ class ShowEpisodeModel: MediaLibraryBaseModel {
var files = [VLCMLMedia]()
var indicatorName: String = NSLocalizedString("EPISODES", comment: "")
var view: MediaLibraryModelView?
var notificaitonName: Notification.Name = .VLCEpisodesDidChangeNotification
var indicatorName: String = NSLocalizedString("EPISODES", comment: "")
required init(medialibrary: VLCMediaLibraryManager) {
medialibrary.addObserver(self)
......@@ -33,6 +33,6 @@ class ShowEpisodeModel: MediaLibraryBaseModel {
extension ShowEpisodeModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddShowEpisode showEpisode: [VLCMLMedia]) {
showEpisode.forEach({ append($0) })
NotificationCenter.default.post(name: notificaitonName, object: nil)
view?.dataChanged()
}
}
......@@ -14,9 +14,9 @@ class VideoModel: MediaLibraryBaseModel {
var files = [VLCMLMedia]()
var indicatorName: String = NSLocalizedString("MOVIES", comment: "")
var view: MediaLibraryModelView?
var notificaitonName: Notification.Name = .VLCVideosDidChangeNotification
var indicatorName: String = NSLocalizedString("MOVIES", comment: "")
required init(medialibrary: VLCMediaLibraryManager) {
medialibrary.addObserver(self)
......@@ -33,6 +33,6 @@ class VideoModel: MediaLibraryBaseModel {
extension VideoModel: MediaLibraryObserver {
func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddVideo video: [VLCMLMedia]) {
video.forEach({ append($0) })
NotificationCenter.default.post(name: notificaitonName, object: nil)
view?.dataChanged()
}
}
......@@ -13,7 +13,7 @@
import Foundation
class VLCMediaCategoryViewController<T, ModelType: MediaLibraryBaseModel>: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchResultsUpdating, UISearchControllerDelegate, IndicatorInfoProvider {
class VLCMediaCategoryViewController<T, ModelType: MediaLibraryBaseModel>: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchResultsUpdating, UISearchControllerDelegate, IndicatorInfoProvider, MediaLibraryModelView {
let cellPadding: CGFloat = 5.0
private var services: Services
private var searchController: UISearchController?
......@@ -42,7 +42,7 @@ class VLCMediaCategoryViewController<T, ModelType: MediaLibraryBaseModel>: UICol
self.category = category
super.init(collectionViewLayout: UICollectionViewFlowLayout())
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: category.notificaitonName, object: nil)
category.view = self
}
override var preferredStatusBarStyle: UIStatusBarStyle {
......@@ -224,3 +224,11 @@ extension VLCMediaCategoryViewController {
VLCPlaybackController.sharedInstance().play(media)
}
}
// MARK: - MediaLibraryModelView
extension VLCMediaCategoryViewController {
func dataChanged() {
reloadData()
}
}
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