Commit 902f2c4b authored by Carola Nitz's avatar Carola Nitz

MediaLibraryBaseModel: move editcell to EditableMLModel protocol

parent 12dbdc7f
...@@ -19,7 +19,6 @@ protocol MediaLibraryBaseModel { ...@@ -19,7 +19,6 @@ protocol MediaLibraryBaseModel {
var indicatorName: String { get } var indicatorName: String { get }
var cellType: BaseCollectionViewCell.Type { get } var cellType: BaseCollectionViewCell.Type { get }
var editCellType: BaseCollectionViewCell.Type { get }
func append(_ item: VLCMLObject) func append(_ item: VLCMLObject)
func delete(_ items: [VLCMLObject]) func delete(_ items: [VLCMLObject])
...@@ -47,10 +46,6 @@ protocol MLBaseModel: AnyObject, MediaLibraryBaseModel { ...@@ -47,10 +46,6 @@ protocol MLBaseModel: AnyObject, MediaLibraryBaseModel {
extension MLBaseModel { extension MLBaseModel {
var editCellType: BaseCollectionViewCell.Type {
return MediaEditCell.self
}
var anyfiles: [VLCMLObject] { var anyfiles: [VLCMLObject] {
return files return files
} }
...@@ -67,3 +62,9 @@ extension MLBaseModel { ...@@ -67,3 +62,9 @@ extension MLBaseModel {
fatalError() fatalError()
} }
} }
protocol EditableMLModel {
func editCellType() -> BaseCollectionViewCell.Type
}
...@@ -31,6 +31,16 @@ class VideoModel: MediaModel { ...@@ -31,6 +31,16 @@ class VideoModel: MediaModel {
} }
} }
// MARK: - Edit
extension VideoModel: EditableMLModel {
func editCellType() -> BaseCollectionViewCell.Type {
return MediaEditCell.self
}
}
// MARK: - Sort // MARK: - Sort
extension VideoModel { extension VideoModel {
......
...@@ -95,8 +95,10 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi ...@@ -95,8 +95,10 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
func setupCollectionView() { func setupCollectionView() {
let cellNib = UINib(nibName: category.cellType.nibName, bundle: nil) let cellNib = UINib(nibName: category.cellType.nibName, bundle: nil)
collectionView?.register(cellNib, forCellWithReuseIdentifier: category.cellType.defaultReuseIdentifier) collectionView?.register(cellNib, forCellWithReuseIdentifier: category.cellType.defaultReuseIdentifier)
let editCellNib = UINib(nibName: category.editCellType.nibName, bundle: nil) if let editCell = (category as? EditableMLModel)?.editCellType() {
collectionView?.register(editCellNib, forCellWithReuseIdentifier: category.editCellType.defaultReuseIdentifier) let editCellNib = UINib(nibName: editCell.nibName, bundle: nil)
collectionView?.register(editCellNib, forCellWithReuseIdentifier: editCell.defaultReuseIdentifier)
}
collectionView?.backgroundColor = PresentationTheme.current.colors.background collectionView?.backgroundColor = PresentationTheme.current.colors.background
collectionView?.alwaysBounceVertical = true collectionView?.alwaysBounceVertical = true
if #available(iOS 11.0, *) { if #available(iOS 11.0, *) {
......
...@@ -191,11 +191,13 @@ extension VLCEditController: UICollectionViewDataSource { ...@@ -191,11 +191,13 @@ extension VLCEditController: UICollectionViewDataSource {
} }
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: category.editCellType.defaultReuseIdentifier, if let editCell = (category as? EditableMLModel)?.editCellType() {
for: indexPath) as? MediaEditCell { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: editCell.defaultReuseIdentifier,
cell.media = category.anyfiles[indexPath.row] for: indexPath) as? MediaEditCell {
cell.isChecked = selectedCellIndexPaths.contains(indexPath) cell.media = category.anyfiles[indexPath.row]
return cell cell.isChecked = selectedCellIndexPaths.contains(indexPath)
return cell
}
} }
return UICollectionViewCell() return UICollectionViewCell()
} }
......
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