ShowEpisodeModel.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*****************************************************************************
  2. * ShowEpisodeModel.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. class ShowEpisodeModel: MLBaseModel {
  12. typealias MLType = VLCMLMedia
  13. var sortModel = SortModel([.alpha, .duration, .insertionDate, .releaseDate, .fileSize])
  14. var updateView: (() -> Void)?
  15. var files = [VLCMLMedia]()
  16. var cellType: BaseCollectionViewCell.Type { return MovieCollectionViewCell.self }
  17. var medialibrary: MediaLibraryService
  18. var indicatorName: String = NSLocalizedString("EPISODES", comment: "")
  19. required init(medialibrary: MediaLibraryService) {
  20. self.medialibrary = medialibrary
  21. medialibrary.addObserver(self)
  22. }
  23. func append(_ item: VLCMLMedia) {
  24. files.append(item)
  25. }
  26. func delete(_ items: [VLCMLObject]) {
  27. preconditionFailure("ShowEpisodeModel: Cannot delete showEpisode")
  28. }
  29. func createPlaylist(_ name: String, _ fileIndexes: Set<IndexPath>? = nil) {
  30. assertionFailure("ShowEpisodeModel: createPlaylist: Not integrated.")
  31. }
  32. }
  33. // MARK: - Sort
  34. extension ShowEpisodeModel {
  35. func sort(by criteria: VLCMLSortingCriteria) {
  36. // Currently no show specific getter on medialibrary.
  37. }
  38. }
  39. // MARK: - MediaLibraryObserver
  40. extension ShowEpisodeModel: MediaLibraryObserver {
  41. func medialibrary(_ medialibrary: MediaLibraryService, didAddShowEpisodes showEpisodes: [VLCMLMedia]) {
  42. showEpisodes.forEach({ append($0) })
  43. updateView?()
  44. }
  45. }