CollectionModel.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // CollectionModel.swift
  3. // VLC-iOS
  4. //
  5. // Created by Carola Nitz on 08.03.19.
  6. // Copyright © 2019 VideoLAN. All rights reserved.
  7. //
  8. import Foundation
  9. class CollectionModel: MLBaseModel {
  10. var sortModel: SortModel
  11. var mediaCollection: MediaCollectionModel
  12. typealias MLType = VLCMLMedia // could be anything
  13. required init(medialibrary: MediaLibraryService) {
  14. preconditionFailure("")
  15. }
  16. required init(mediaService: MediaLibraryService, mediaCollection: MediaCollectionModel) {
  17. self.medialibrary = mediaService
  18. self.mediaCollection = mediaCollection
  19. files = mediaCollection.files()
  20. sortModel = mediaCollection.sortModel() ?? SortModel([.default])
  21. medialibrary.addObserver(self)
  22. }
  23. func append(_ item: VLCMLMedia) {
  24. files.append(item)
  25. }
  26. var medialibrary: MediaLibraryService
  27. var updateView: (() -> Void)?
  28. var files = [VLCMLMedia]()
  29. var cellType: BaseCollectionViewCell.Type { return MediaCollectionViewCell.self }
  30. var indicatorName: String = NSLocalizedString("Collections", comment: "")
  31. func delete(_ items: [VLCMLObject]) {
  32. assertionFailure("still needs implementation")
  33. }
  34. func createPlaylist(_ name: String, _ fileIndexes: Set<IndexPath>?) {
  35. assertionFailure("still needs implementation")
  36. }
  37. }
  38. // MARK: - Edit
  39. extension CollectionModel: EditableMLModel {
  40. func editCellType() -> BaseCollectionViewCell.Type {
  41. return MediaEditCell.self
  42. }
  43. }
  44. // MARK: - MediaLibraryObserver
  45. extension CollectionModel: MediaLibraryObserver {
  46. func medialibrary(_ medialibrary: MediaLibraryService, didModifyPlaylists playlists: [VLCMLPlaylist]) {
  47. if mediaCollection is VLCMLPlaylist {
  48. files = mediaCollection.files()
  49. updateView?()
  50. }
  51. }
  52. }