AlbumModel.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 medialibrary: VLCMediaLibraryManager
  16. var indicatorName: String = NSLocalizedString("ALBUMS", comment: "")
  17. required init(medialibrary: VLCMediaLibraryManager) {
  18. self.medialibrary = medialibrary
  19. medialibrary.addObserver(self)
  20. files = medialibrary.getAlbums()
  21. }
  22. func append(_ item: VLCMLAlbum) {
  23. files.append(item)
  24. }
  25. func delete(_ items: [VLCMLObject]) {
  26. preconditionFailure("AlbumModel: Cannot delete album")
  27. }
  28. }
  29. extension AlbumModel: MediaLibraryObserver {
  30. func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddAlbums albums: [VLCMLAlbum]) {
  31. albums.forEach({ append($0) })
  32. updateView?()
  33. }
  34. }