AlbumModel.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*****************************************************************************
  2. * AlbumModel.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 AlbumModel: MLBaseModel {
  12. typealias MLType = VLCMLAlbum
  13. var updateView: (() -> Void)?
  14. var files = [VLCMLAlbum]()
  15. var cellType: BaseCollectionViewCell.Type { return MovieCollectionViewCell.self }
  16. var medialibrary: VLCMediaLibraryManager
  17. var indicatorName: String = NSLocalizedString("ALBUMS", comment: "")
  18. required init(medialibrary: VLCMediaLibraryManager) {
  19. self.medialibrary = medialibrary
  20. medialibrary.addObserver(self)
  21. files = medialibrary.getAlbums()
  22. }
  23. func append(_ item: VLCMLAlbum) {
  24. files.append(item)
  25. }
  26. func delete(_ items: [VLCMLObject]) {
  27. preconditionFailure("AlbumModel: Cannot delete album")
  28. }
  29. }
  30. extension AlbumModel: MediaLibraryObserver {
  31. func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddAlbums albums: [VLCMLAlbum]) {
  32. albums.forEach({ append($0) })
  33. updateView?()
  34. }
  35. }