MediaLibraryBaseModel.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*****************************************************************************
  2. * MediaLibraryBaseModel.swift
  3. *
  4. * Copyright © 2018 VLC authors and VideoLAN
  5. * Copyright © 2018 Videolabs
  6. *
  7. * Authors: Soomin Lee <bubu@mikan.io>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. // Expose a "shadow" version without associatedType in order to use it as a type
  12. protocol MediaLibraryBaseModel {
  13. init(medialibrary: MediaLibraryService)
  14. var anyfiles: [VLCMLObject] { get }
  15. var sortModel: SortModel { get }
  16. var updateView: (() -> Void)? { get set }
  17. var indicatorName: String { get }
  18. var cellType: BaseCollectionViewCell.Type { get }
  19. func append(_ item: VLCMLObject)
  20. func delete(_ items: [VLCMLObject])
  21. func sort(by criteria: VLCMLSortingCriteria)
  22. func createPlaylist(_ name: String, _ fileIndexes: Set<IndexPath>?)
  23. }
  24. protocol MLBaseModel: AnyObject, MediaLibraryBaseModel {
  25. associatedtype MLType where MLType: VLCMLObject
  26. init(medialibrary: MediaLibraryService)
  27. var files: [MLType] { get set }
  28. var medialibrary: MediaLibraryService { get }
  29. var updateView: (() -> Void)? { get set }
  30. var indicatorName: String { get }
  31. func append(_ item: MLType)
  32. // FIXME: Ideally items should be MLType but Swift isn't happy so it will always fail
  33. func delete(_ items: [VLCMLObject])
  34. func sort(by criteria: VLCMLSortingCriteria)
  35. func createPlaylist(_ name: String, _ fileIndexes: Set<IndexPath>?)
  36. }
  37. extension MLBaseModel {
  38. var anyfiles: [VLCMLObject] {
  39. return files
  40. }
  41. func append(_ item: VLCMLObject) {
  42. fatalError()
  43. }
  44. func delete(_ items: [VLCMLObject]) {
  45. fatalError()
  46. }
  47. func sort(by criteria: VLCMLSortingCriteria) {
  48. fatalError()
  49. }
  50. }
  51. protocol EditableMLModel {
  52. func editCellType() -> BaseCollectionViewCell.Type
  53. }
  54. protocol MediaCollectionModel {
  55. func files() -> [VLCMLMedia]
  56. func sortModel() -> SortModel?
  57. }