瀏覽代碼

MediaLibraryBaseModel: move editcell to EditableMLModel protocol

Carola Nitz 6 年之前
父節點
當前提交
902f2c4bfa

+ 6 - 5
SharedSources/MediaLibraryModel/MediaLibraryBaseModel.swift

@@ -19,7 +19,6 @@ protocol MediaLibraryBaseModel {
 
     var indicatorName: String { get }
     var cellType: BaseCollectionViewCell.Type { get }
-    var editCellType: BaseCollectionViewCell.Type { get }
 
     func append(_ item: VLCMLObject)
     func delete(_ items: [VLCMLObject])
@@ -47,10 +46,6 @@ protocol MLBaseModel: AnyObject, MediaLibraryBaseModel {
 
 extension MLBaseModel {
 
-    var editCellType: BaseCollectionViewCell.Type {
-        return MediaEditCell.self
-    }
-
     var anyfiles: [VLCMLObject] {
         return files
     }
@@ -67,3 +62,9 @@ extension MLBaseModel {
         fatalError()
     }
 }
+
+protocol EditableMLModel {
+
+    func editCellType() -> BaseCollectionViewCell.Type
+
+}

+ 10 - 0
SharedSources/MediaLibraryModel/VideoModel.swift

@@ -31,6 +31,16 @@ class VideoModel: MediaModel {
     }
 }
 
+// MARK: - Edit
+
+extension VideoModel: EditableMLModel {
+
+    func editCellType() -> BaseCollectionViewCell.Type {
+        return MediaEditCell.self
+    }
+
+}
+
 // MARK: - Sort
 
 extension VideoModel {

+ 4 - 2
Sources/MediaCategories/MediaCategoryViewController.swift

@@ -95,8 +95,10 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
     func setupCollectionView() {
         let cellNib = UINib(nibName: category.cellType.nibName, bundle: nil)
         collectionView?.register(cellNib, forCellWithReuseIdentifier: category.cellType.defaultReuseIdentifier)
-        let editCellNib = UINib(nibName: category.editCellType.nibName, bundle: nil)
-        collectionView?.register(editCellNib, forCellWithReuseIdentifier: category.editCellType.defaultReuseIdentifier)
+        if let editCell = (category as? EditableMLModel)?.editCellType() {
+            let editCellNib = UINib(nibName: editCell.nibName, bundle: nil)
+            collectionView?.register(editCellNib, forCellWithReuseIdentifier: editCell.defaultReuseIdentifier)
+        }
         collectionView?.backgroundColor = PresentationTheme.current.colors.background
         collectionView?.alwaysBounceVertical = true
         if #available(iOS 11.0, *) {

+ 7 - 5
Sources/VLCEditController.swift

@@ -191,11 +191,13 @@ extension VLCEditController: UICollectionViewDataSource {
     }
 
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-        if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: category.editCellType.defaultReuseIdentifier,
-                                                         for: indexPath) as? MediaEditCell {
-            cell.media = category.anyfiles[indexPath.row]
-            cell.isChecked = selectedCellIndexPaths.contains(indexPath)
-            return cell
+        if let editCell = (category as? EditableMLModel)?.editCellType() {
+            if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: editCell.defaultReuseIdentifier,
+                                                             for: indexPath) as? MediaEditCell {
+                cell.media = category.anyfiles[indexPath.row]
+                cell.isChecked = selectedCellIndexPaths.contains(indexPath)
+                return cell
+            }
         }
         return UICollectionViewCell()
     }