ShowEpisodeModel.swift 1.7 KB

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