MediaLibraryBaseModel.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. }
  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)
  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) {
  46. fatalError()
  47. }
  48. }
  49. protocol EditableMLModel {
  50. func editCellType() -> BaseCollectionViewCell.Type
  51. }