123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /*****************************************************************************
- * GenreModel.swift
- *
- * Copyright © 2018 VLC authors and VideoLAN
- * Copyright © 2018 Videolabs
- *
- * Authors: Soomin Lee <bubu@mikan.io>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- class GenreModel: MLBaseModel {
- typealias MLType = VLCMLGenre
- var sortModel = SortModel([.alpha])
- var updateView: (() -> Void)?
- var files = [VLCMLGenre]()
- var cellType: BaseCollectionViewCell.Type { return MediaCollectionViewCell.self }
- var medialibrary: MediaLibraryService
- var indicatorName: String = NSLocalizedString("GENRES", comment: "")
- required init(medialibrary: MediaLibraryService) {
- self.medialibrary = medialibrary
- medialibrary.addObserver(self)
- files = medialibrary.genres()
- }
- func append(_ item: VLCMLGenre) {
- files.append(item)
- }
- func delete(_ items: [VLCMLObject]) {
- preconditionFailure("GenreModel: Genres can not be deleted, they disappear when their last title got deleted")
- }
- }
- // MARK: - Sort
- extension GenreModel {
- func sort(by criteria: VLCMLSortingCriteria) {
- files = medialibrary.genres(sortingCriteria: criteria)
- sortModel.currentSort = criteria
- updateView?()
- }
- }
- // MARK: - MediaLibraryObserver
- extension GenreModel: MediaLibraryObserver {
- func medialibrary(_ medialibrary: MediaLibraryService, didAddGenres genres: [VLCMLGenre]) {
- genres.forEach({ append($0) })
- updateView?()
- }
- }
- // MARK: - Edit
- extension GenreModel: EditableMLModel {
- func editCellType() -> BaseCollectionViewCell.Type {
- return MediaEditCell.self
- }
- }
- // MARK: - Helpers
- extension VLCMLGenre {
- @objc func numberOfTracksString() -> String {
- let numberOftracks = numberOfTracks()
- if numberOftracks != 1 {
- return String(format: NSLocalizedString("TRACKS", comment: ""), numberOftracks)
- }
- return String(format: NSLocalizedString("TRACK", comment: ""), numberOftracks)
- }
- }
- extension VLCMLGenre: MediaCollectionModel {
- func sortModel() -> SortModel? {
- return SortModel([.alpha])
- }
- func files() -> [VLCMLMedia]? {
- return tracks()
- }
- }
|