Browse Source

Cosmetic: Rename category to model

Soomin Lee 6 years ago
parent
commit
f277ed86ba

+ 14 - 14
Sources/MediaCategories/MediaCategory.swift

@@ -13,8 +13,8 @@
 class VLCMovieCategoryViewController: VLCMediaCategoryViewController {
     init(_ services: Services) {
         let model = VideoModel(medialibrary: services.medialibraryManager)
-        super.init(services: services, category: model)
-        category.updateView = { [weak self] in
+        super.init(services: services, model: model)
+        model.updateView = { [weak self] in
             self?.reloadData()
         }
     }
@@ -23,8 +23,8 @@ class VLCMovieCategoryViewController: VLCMediaCategoryViewController {
 class VLCShowEpisodeCategoryViewController: VLCMediaCategoryViewController {
     init(_ services: Services) {
         let model = ShowEpisodeModel(medialibrary: services.medialibraryManager)
-        super.init(services: services, category: model)
-        category.updateView = { [weak self] in
+        super.init(services: services, model: model)
+        model.updateView = { [weak self] in
             self?.reloadData()
         }
     }
@@ -33,8 +33,8 @@ class VLCShowEpisodeCategoryViewController: VLCMediaCategoryViewController {
 class VLCPlaylistCategoryViewController: VLCMediaCategoryViewController {
     init(_ services: Services) {
         let model = PlaylistModel(medialibrary: services.medialibraryManager)
-        super.init(services: services, category: model)
-        category.updateView = { [weak self] in
+        super.init(services: services, model: model)
+        model.updateView = { [weak self] in
             self?.reloadData()
         }
     }
@@ -43,8 +43,8 @@ class VLCPlaylistCategoryViewController: VLCMediaCategoryViewController {
 class VLCTrackCategoryViewController: VLCMediaCategoryViewController {
     init(_ services: Services) {
         let model = AudioModel(medialibrary: services.medialibraryManager)
-        super.init(services: services, category: model)
-        category.updateView = { [weak self] in
+        super.init(services: services, model: model)
+        model.updateView = { [weak self] in
             self?.reloadData()
         }
     }
@@ -53,8 +53,8 @@ class VLCTrackCategoryViewController: VLCMediaCategoryViewController {
 class VLCGenreCategoryViewController: VLCMediaCategoryViewController {
     init(_ services: Services) {
         let model = GenreModel(medialibrary: services.medialibraryManager)
-        super.init(services: services, category: model)
-        category.updateView = { [weak self] in
+        super.init(services: services, model: model)
+        model.updateView = { [weak self] in
             self?.reloadData()
         }
     }
@@ -63,8 +63,8 @@ class VLCGenreCategoryViewController: VLCMediaCategoryViewController {
 class VLCArtistCategoryViewController: VLCMediaCategoryViewController {
     init(_ services: Services) {
         let model = ArtistModel(medialibrary: services.medialibraryManager)
-        super.init(services: services, category: model)
-        category.updateView = { [weak self] in
+        super.init(services: services, model: model)
+        model.updateView = { [weak self] in
             self?.reloadData()
         }
     }
@@ -73,8 +73,8 @@ class VLCArtistCategoryViewController: VLCMediaCategoryViewController {
 class VLCAlbumCategoryViewController: VLCMediaCategoryViewController {
     init(_ services: Services) {
         let model = AlbumModel(medialibrary: services.medialibraryManager)
-        super.init(services: services, category: model)
-        category.updateView = { [weak self] in
+        super.init(services: services, model: model)
+        model.updateView = { [weak self] in
             self?.reloadData()
         }
     }

+ 21 - 21
Sources/MediaCategories/MediaCategoryViewController.swift

@@ -15,14 +15,14 @@ import Foundation
 
 class VLCMediaCategoryViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UISearchResultsUpdating, UISearchControllerDelegate, IndicatorInfoProvider {
 
-    var category: MediaLibraryBaseModel
+    var model: MediaLibraryBaseModel
 
     private var services: Services
     private var searchController: UISearchController?
     private let searchDataSource = VLCLibrarySearchDisplayDataSource()
-    private lazy var editController = VLCEditController(collectionView: self.collectionView!, category: self.category)
+    private lazy var editController = VLCEditController(collectionView: self.collectionView!, model: self.model)
     private lazy var editToolbar: VLCEditToolbar = {
-        let editToolbar = VLCEditToolbar(category: category)
+        let editToolbar = VLCEditToolbar(category: model)
         editToolbar.delegate = editController
         return editToolbar
     }()
@@ -53,9 +53,9 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
         fatalError()
     }
 
-    init(services: Services, category: MediaLibraryBaseModel) {
+    init(services: Services, model: MediaLibraryBaseModel) {
         self.services = services
-        self.category = category
+        self.model = model
         super.init(collectionViewLayout: UICollectionViewFlowLayout())
         NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
     }
@@ -102,9 +102,9 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
     }
 
     func setupCollectionView() {
-        let cellNib = UINib(nibName: category.cellType.nibName, bundle: nil)
-        collectionView?.register(cellNib, forCellWithReuseIdentifier: category.cellType.defaultReuseIdentifier)
-        if let editCell = (category as? EditableMLModel)?.editCellType() {
+        let cellNib = UINib(nibName: model.cellType.nibName, bundle: nil)
+        collectionView?.register(cellNib, forCellWithReuseIdentifier: model.cellType.defaultReuseIdentifier)
+        if let editCell = (model as? EditableMLModel)?.editCellType() {
             let editCellNib = UINib(nibName: editCell.nibName, bundle: nil)
             collectionView?.register(editCellNib, forCellWithReuseIdentifier: editCell.defaultReuseIdentifier)
         }
@@ -201,7 +201,7 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
     // MARK: - Search
 
     func updateSearchResults(for searchController: UISearchController) {
-        searchDataSource.shouldReloadTable(forSearch: searchController.searchBar.text, searchableFiles: category.anyfiles)
+        searchDataSource.shouldReloadTable(forSearch: searchController.searchBar.text, searchableFiles: model.anyfiles)
         collectionView?.reloadData()
     }
 
@@ -214,20 +214,20 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
     }
 
     func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
-        return IndicatorInfo(title:category.indicatorName)
+        return IndicatorInfo(title:model.indicatorName)
     }
 
     // MARK: - UICollectionViewDataSource
     override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return category.anyfiles.count
+        return model.anyfiles.count
     }
 
     override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-        guard let mediaCell = collectionView.dequeueReusableCell(withReuseIdentifier:category.cellType.defaultReuseIdentifier, for: indexPath) as? BaseCollectionViewCell else {
+        guard let mediaCell = collectionView.dequeueReusableCell(withReuseIdentifier:model.cellType.defaultReuseIdentifier, for: indexPath) as? BaseCollectionViewCell else {
             assertionFailure("you forgot to register the cell or the cell is not a subclass of BaseCollectionViewCell")
             return UICollectionViewCell()
         }
-        let mediaObject = category.anyfiles[indexPath.row]
+        let mediaObject = model.anyfiles[indexPath.row]
         if let media = mediaObject as? VLCMLMedia {
             assert(media.mainFile() != nil, "The mainfile is nil")
             mediaCell.media = media.mainFile() != nil ? media : nil
@@ -239,7 +239,7 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
 
     // MARK: - UICollectionViewDelegate
     override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-        if let media = category.anyfiles[indexPath.row] as? VLCMLMedia {
+        if let media = model.anyfiles[indexPath.row] as? VLCMLMedia {
             play(media: media)
         }
     }
@@ -247,21 +247,21 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
     // MARK: - UICollectionViewDelegateFlowLayout
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
         if cachedCellSize == .zero {
-            cachedCellSize = category.cellType.cellSizeForWidth(collectionView.frame.size.width)
+            cachedCellSize = model.cellType.cellSizeForWidth(collectionView.frame.size.width)
         }
         return cachedCellSize
     }
 
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
-        return UIEdgeInsets(top: category.cellType.cellPadding, left: category.cellType.cellPadding, bottom: category.cellType.cellPadding, right: category.cellType.cellPadding)
+        return UIEdgeInsets(top: model.cellType.cellPadding, left: model.cellType.cellPadding, bottom: model.cellType.cellPadding, right: model.cellType.cellPadding)
     }
 
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
-        return category.cellType.cellPadding
+        return model.cellType.cellPadding
     }
 
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
-        return category.cellType.cellPadding
+        return model.cellType.cellPadding
     }
 }
 
@@ -271,15 +271,15 @@ extension VLCMediaCategoryViewController {
     // FIXME: Need to add a button for ascending/descending result
     func sortByFileName() {
         // The issue is that for audio we show title which is quite confusing if we use filename
-        category.sort(by: .alpha)
+        model.sort(by: .alpha)
     }
 
     func sortByDate() {
-        category.sort(by: .insertionDate)
+        model.sort(by: .insertionDate)
     }
 
     func sortBySize() {
-        category.sort(by: .fileSize)
+        model.sort(by: .fileSize)
     }
 }
 

+ 13 - 13
Sources/VLCEditController.swift

@@ -12,11 +12,11 @@
 class VLCEditController: NSObject {
     private var selectedCellIndexPaths = Set<IndexPath>()
     private let collectionView: UICollectionView
-    private let category: MediaLibraryBaseModel
+    private let model: MediaLibraryBaseModel
 
-    init(collectionView: UICollectionView, category: MediaLibraryBaseModel) {
+    init(collectionView: UICollectionView, model: MediaLibraryBaseModel) {
         self.collectionView = collectionView
-        self.category = category
+        self.model = model
         super.init()
     }
 
@@ -87,7 +87,7 @@ private extension VLCEditController {
 
 extension VLCEditController: VLCEditToolbarDelegate {
     func createPlaylist() {
-        if let model = category as? PlaylistModel {
+        if let model = model as? PlaylistModel {
             let alertInfo = TextFieldAlertInfo(alertTitle: NSLocalizedString("PLAYLISTS", comment: ""),
                 placeHolder: "NEW_PLAYLIST")
 
@@ -96,15 +96,15 @@ extension VLCEditController: VLCEditToolbarDelegate {
                     model.create(name: text)
                 })
 
-        } else if let model = category as? VideoModel {
+        } else if let model = model as? VideoModel {
             let alertInfo = TextFieldAlertInfo(alertTitle: NSLocalizedString("PLAYLISTS", comment: ""),
                                                placeHolder: "NEW_PLAYLIST")
 
             presentTextFieldAlert(with: alertInfo, completionHandler: {
-                [selectedCellIndexPaths, category] text -> Void in
+                [selectedCellIndexPaths, model] text -> Void in
                 let playlist = model.medialibrary.createPlaylist(with: text)
                 for indexPath in selectedCellIndexPaths {
-                    if let media = category.anyfiles[indexPath.row] as? VLCMLMedia {
+                    if let media = model.anyfiles[indexPath.row] as? VLCMLMedia {
                         playlist.appendMedia(withIdentifier: media.identifier())
                     }
                 }
@@ -116,7 +116,7 @@ extension VLCEditController: VLCEditToolbarDelegate {
         var objectsToDelete = [VLCMLObject]()
 
         for indexPath in selectedCellIndexPaths {
-            objectsToDelete.append(category.anyfiles[indexPath.row])
+            objectsToDelete.append(model.anyfiles[indexPath.row])
         }
 
         let cancelButton = VLCAlertButton(title: NSLocalizedString("BUTTON_CANCEL", comment: ""))
@@ -124,7 +124,7 @@ extension VLCEditController: VLCEditToolbarDelegate {
                                           style: .destructive,
                                           action: {
                                             [weak self] action in
-                                            self?.category.delete(objectsToDelete)
+                                            self?.model.delete(objectsToDelete)
                                             self?.selectedCellIndexPaths.removeAll()
                                             self?.resetAllVisibleCell()
         })
@@ -143,7 +143,7 @@ extension VLCEditController: VLCEditToolbarDelegate {
     func rename() {
         // FIXME: Multiple renaming of files(multiple alert can get unfriendly if too many files)
         for indexPath in selectedCellIndexPaths {
-            if let media = category.anyfiles[indexPath.row] as? VLCMLMedia {
+            if let media = model.anyfiles[indexPath.row] as? VLCMLMedia {
                 // Not using VLCAlertViewController to have more customization in text fields
                 let alertInfo = TextFieldAlertInfo(alertTitle: String(format: NSLocalizedString("RENAME_MEDIA_TO", comment: ""), media.title),
                                                    placeHolder: "NEW_NAME",
@@ -168,17 +168,17 @@ extension VLCEditController: VLCEditToolbarDelegate {
 
 extension VLCEditController: UICollectionViewDataSource {
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return category.anyfiles.count
+        return model.anyfiles.count
     }
 
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-        guard let editCell = (category as? EditableMLModel)?.editCellType() else {
+        guard let editCell = (model as? EditableMLModel)?.editCellType() else {
             assertionFailure("The category either doesn't implement EditableMLModel or doesn't have a editcellType defined")
             return UICollectionViewCell()
         }
         if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: editCell.defaultReuseIdentifier,
                                                          for: indexPath) as? MediaEditCell {
-            cell.media = category.anyfiles[indexPath.row]
+            cell.media = model.anyfiles[indexPath.row]
             cell.isChecked = selectedCellIndexPaths.contains(indexPath)
             return cell
         } else {