MediaLibraryBaseModel.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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: VLCMediaLibraryManager)
  14. var anyfiles: [VLCMLObject] { get }
  15. var updateView: (() -> Void)? { get set }
  16. var indicatorName: String { get }
  17. var cellType: BaseCollectionViewCell.Type { get }
  18. func append(_ item: VLCMLObject)
  19. func delete(_ items: [VLCMLObject])
  20. func sort(by criteria: VLCMLSortingCriteria)
  21. }
  22. protocol MLBaseModel: AnyObject, MediaLibraryBaseModel {
  23. associatedtype MLType where MLType: VLCMLObject
  24. init(medialibrary: VLCMediaLibraryManager)
  25. var files: [MLType] { get set }
  26. var medialibrary: VLCMediaLibraryManager { get }
  27. var updateView: (() -> Void)? { get set }
  28. var indicatorName: String { get }
  29. func append(_ item: MLType)
  30. // FIXME: Ideally items should be MLType but Swift isn't happy so it will always fail
  31. func delete(_ items: [VLCMLObject])
  32. func sort(by criteria: VLCMLSortingCriteria)
  33. }
  34. extension MLBaseModel {
  35. var anyfiles: [VLCMLObject] {
  36. return files
  37. }
  38. func append(_ item: VLCMLObject) {
  39. fatalError()
  40. }
  41. func delete(_ items: [VLCMLObject]) {
  42. fatalError()
  43. }
  44. func sort(by criteria: VLCMLSortingCriteria) {
  45. fatalError()
  46. }
  47. }
  48. protocol EditableMLModel {
  49. func editCellType() -> BaseCollectionViewCell.Type
  50. }