GenreModel.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*****************************************************************************
  2. * GenreModel.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 GenreModel: MLBaseModel {
  12. typealias MLType = VLCMLGenre
  13. var updateView: (() -> Void)?
  14. var files = [VLCMLGenre]()
  15. var medialibrary: VLCMediaLibraryManager
  16. var indicatorName: String = NSLocalizedString("GENRE", comment: "")
  17. required init(medialibrary: VLCMediaLibraryManager) {
  18. self.medialibrary = medialibrary
  19. medialibrary.addObserver(self)
  20. // created too late so missed the callback asking if he has anything
  21. files = medialibrary.genre()
  22. }
  23. func isIncluded(_ item: VLCMLGenre) {
  24. }
  25. func append(_ item: VLCMLGenre) {
  26. // need to check more for duplicate and stuff
  27. files.append(item)
  28. }
  29. }
  30. extension GenreModel: MediaLibraryObserver {
  31. func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddGenre genre: [VLCMLGenre]) {
  32. genre.forEach({ append($0) })
  33. updateView?()
  34. }
  35. }