Commit 74a91466 authored by Soomin Lee's avatar Soomin Lee

MediaLibraryBaseModel: Hide associatedType logic

parent ed520ad9
......@@ -9,7 +9,7 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
class AlbumModel: MediaLibraryBaseModel {
class AlbumModel: MLBaseModel {
typealias MLType = VLCMLAlbum
var updateView: (() -> Void)?
......
......@@ -9,7 +9,7 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
class ArtistModel: MediaLibraryBaseModel {
class ArtistModel: MLBaseModel {
typealias MLType = VLCMLArtist
var updateView: (() -> Void)?
......
......@@ -9,7 +9,7 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
class AudioModel: MediaLibraryBaseModel {
class AudioModel: MLBaseModel {
typealias MLType = VLCMLMedia
var updateView: (() -> Void)?
......
......@@ -9,7 +9,7 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
class GenreModel: MediaLibraryBaseModel {
class GenreModel: MLBaseModel {
typealias MLType = VLCMLGenre
var updateView: (() -> Void)?
......
......@@ -13,7 +13,21 @@ protocol MediaLibraryModelView {
func dataChanged()
}
protocol MediaLibraryBaseModel: class {
// Expose a "shadow" version without associatedType in order to use it as a type
protocol MediaLibraryBaseModel {
init(medialibrary: VLCMediaLibraryManager)
var anyfiles: [VLCMLObject] { get }
var updateView: (() -> Void)? { get set }
var indicatorName: String { get }
func append(_ item: VLCMLObject)
func isIncluded(_ item: VLCMLObject)
}
protocol MLBaseModel: MediaLibraryBaseModel {
associatedtype MLType where MLType: VLCMLObject
init(medialibrary: VLCMediaLibraryManager)
......@@ -27,3 +41,17 @@ protocol MediaLibraryBaseModel: class {
func append(_ item: MLType)
func isIncluded(_ item: MLType)
}
extension MLBaseModel {
var anyfiles: [VLCMLObject] {
return files
}
func append(_ item: VLCMLObject) {
fatalError()
}
func isIncluded(_ item: VLCMLObject) {
fatalError()
}
}
......@@ -9,7 +9,7 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
class ShowEpisodeModel: MediaLibraryBaseModel {
class ShowEpisodeModel: MLBaseModel {
typealias MLType = VLCMLMedia
var updateView: (() -> Void)?
......
......@@ -9,7 +9,7 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
class VideoModel: MediaLibraryBaseModel {
class VideoModel: MLBaseModel {
typealias MLType = VLCMLMedia
var updateView: (() -> Void)?
......
......@@ -10,7 +10,7 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
class VLCMovieCategoryViewController: VLCMediaCategoryViewController<VideoModel> {
class VLCMovieCategoryViewController: VLCMediaCategoryViewController {
init(_ services: Services) {
let model = VideoModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
......@@ -20,7 +20,7 @@ class VLCMovieCategoryViewController: VLCMediaCategoryViewController<VideoModel>
}
}
class VLCShowEpisodeCategoryViewController: VLCMediaCategoryViewController<ShowEpisodeModel> {
class VLCShowEpisodeCategoryViewController: VLCMediaCategoryViewController {
init(_ services: Services) {
let model = ShowEpisodeModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
......@@ -30,7 +30,7 @@ class VLCShowEpisodeCategoryViewController: VLCMediaCategoryViewController<ShowE
}
}
class VLCVideoPlaylistCategoryViewController: VLCMediaCategoryViewController<VideoModel> {
class VLCVideoPlaylistCategoryViewController: VLCMediaCategoryViewController {
init(_ services: Services) {
let model = VideoModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
......@@ -40,7 +40,7 @@ class VLCVideoPlaylistCategoryViewController: VLCMediaCategoryViewController<Vid
}
}
class VLCTrackCategoryViewController: VLCMediaCategoryViewController<AudioModel> {
class VLCTrackCategoryViewController: VLCMediaCategoryViewController {
init(_ services: Services) {
let model = AudioModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
......@@ -50,7 +50,7 @@ class VLCTrackCategoryViewController: VLCMediaCategoryViewController<AudioModel>
}
}
class VLCGenreCategoryViewController: VLCMediaCategoryViewController<GenreModel> {
class VLCGenreCategoryViewController: VLCMediaCategoryViewController {
init(_ services: Services) {
let model = GenreModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
......@@ -60,7 +60,7 @@ class VLCGenreCategoryViewController: VLCMediaCategoryViewController<GenreModel>
}
}
class VLCArtistCategoryViewController: VLCMediaCategoryViewController<ArtistModel> {
class VLCArtistCategoryViewController: VLCMediaCategoryViewController {
init(_ services: Services) {
let model = ArtistModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
......@@ -70,7 +70,7 @@ class VLCArtistCategoryViewController: VLCMediaCategoryViewController<ArtistMode
}
}
class VLCAlbumCategoryViewController: VLCMediaCategoryViewController<AlbumModel> {
class VLCAlbumCategoryViewController: VLCMediaCategoryViewController {
init(_ services: Services) {
let model = AlbumModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
......@@ -80,7 +80,7 @@ class VLCAlbumCategoryViewController: VLCMediaCategoryViewController<AlbumModel>
}
}
class VLCAudioPlaylistCategoryViewController: VLCMediaCategoryViewController<VideoModel> {
class VLCAudioPlaylistCategoryViewController: VLCMediaCategoryViewController {
init(_ services: Services) {
let model = VideoModel(medialibrary: services.medialibraryManager)
super.init(services: services, category: model)
......
......@@ -13,12 +13,12 @@
import Foundation
class VLCMediaCategoryViewController<ModelType: MediaLibraryBaseModel>: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchResultsUpdating, UISearchControllerDelegate, IndicatorInfoProvider, MediaLibraryModelView {
class VLCMediaCategoryViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchResultsUpdating, UISearchControllerDelegate, IndicatorInfoProvider, MediaLibraryModelView {
let cellPadding: CGFloat = 5.0
private var services: Services
private var searchController: UISearchController?
private let searchDataSource = VLCLibrarySearchDisplayDataSource()
var category: ModelType
var category: MediaLibraryBaseModel
// @available(iOS 11.0, *)
// lazy var dragAndDropManager: VLCDragAndDropManager = { () -> VLCDragAndDropManager<T> in
......@@ -37,7 +37,7 @@ class VLCMediaCategoryViewController<ModelType: MediaLibraryBaseModel>: UICollec
fatalError()
}
init(services: Services, category: ModelType) {
init(services: Services, category: MediaLibraryBaseModel) {
self.services = services
self.category = category
super.init(collectionViewLayout: UICollectionViewFlowLayout())
......@@ -137,7 +137,7 @@ class VLCMediaCategoryViewController<ModelType: MediaLibraryBaseModel>: UICollec
// MARK: - Search
func updateSearchResults(for searchController: UISearchController) {
searchDataSource.shouldReloadTable(forSearch: searchController.searchBar.text, searchableFiles: category.files)
searchDataSource.shouldReloadTable(forSearch: searchController.searchBar.text, searchableFiles: category.anyfiles)
collectionView?.reloadData()
}
......@@ -155,16 +155,16 @@ class VLCMediaCategoryViewController<ModelType: MediaLibraryBaseModel>: UICollec
// MARK: - UICollectionViewDataSource
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return category.files.count
return category.anyfiles.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let playlistCell = collectionView.dequeueReusableCell(withReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier(), for: indexPath) as? VLCPlaylistCollectionViewCell {
if let mediaObject = category.files[indexPath.row] as? NSManagedObject {
if let mediaObject = category.anyfiles[indexPath.row] as? NSManagedObject {
playlistCell.mediaObject = mediaObject
}
if let media = category.files[indexPath.row] as? VLCMLMedia {
if let media = category.anyfiles[indexPath.row] as? VLCMLMedia {
playlistCell.media = media
if media.mainFile() == nil {
playlistCell.media = nil
......@@ -177,9 +177,9 @@ class VLCMediaCategoryViewController<ModelType: MediaLibraryBaseModel>: UICollec
// MARK: - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let mediaObject = category.files[indexPath.row] as? NSManagedObject {
if let mediaObject = category.anyfiles[indexPath.row] as? NSManagedObject {
play(mediaObject: mediaObject)
} else if let media = category.files[indexPath.row] as? VLCMLMedia {
} else if let media = category.anyfiles[indexPath.row] as? VLCMLMedia {
play(media: media)
}
}
......
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