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

MediaLibraryBaseModel: move editcell to EditableMLModel protocol

parent 12dbdc7f
......@@ -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
}
......@@ -31,6 +31,16 @@ class VideoModel: MediaModel {
}
}
// MARK: - Edit
extension VideoModel: EditableMLModel {
func editCellType() -> BaseCollectionViewCell.Type {
return MediaEditCell.self
}
}
// MARK: - Sort
extension VideoModel {
......
......@@ -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, *) {
......
......@@ -191,12 +191,14 @@ extension VLCEditController: UICollectionViewDataSource {
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: category.editCellType.defaultReuseIdentifier,
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()
}
}
......
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