MediaLibraryBaseModel.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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, desc: Bool)
  22. }
  23. protocol MLBaseModel: AnyObject, MediaLibraryBaseModel {
  24. associatedtype MLType where MLType: VLCMLObject
  25. init(medialibrary: MediaLibraryService)
  26. var files: [MLType] { get set }
  27. var medialibrary: MediaLibraryService { get }
  28. var updateView: (() -> Void)? { get set }
  29. var indicatorName: String { get }
  30. func append(_ item: MLType)
  31. // FIXME: Ideally items should be MLType but Swift isn't happy so it will always fail
  32. func delete(_ items: [VLCMLObject])
  33. func sort(by criteria: VLCMLSortingCriteria, desc: Bool)
  34. }
  35. extension MLBaseModel {
  36. var anyfiles: [VLCMLObject] {
  37. return files
  38. }
  39. func append(_ item: VLCMLObject) {
  40. fatalError()
  41. }
  42. func delete(_ items: [VLCMLObject]) {
  43. fatalError()
  44. }
  45. func sort(by criteria: VLCMLSortingCriteria, desc: Bool) {
  46. fatalError()
  47. }
  48. }
  49. protocol EditableMLModel {
  50. func editCellType() -> BaseCollectionViewCell.Type
  51. }
  52. protocol SearchableMLModel {
  53. func contains(_ searchString: String) -> Bool
  54. }
  55. protocol MediaCollectionModel {
  56. func files() -> [VLCMLMedia]?
  57. func sortModel() -> SortModel?
  58. func title() -> String?
  59. }