ArtistModel.swift 1.08 KB
Newer Older
Soomin Lee's avatar
Soomin Lee committed
1 2 3 4 5 6 7 8 9 10 11
/*****************************************************************************
 * ArtistModel.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.
 *****************************************************************************/

12
class ArtistModel: MLBaseModel {
Soomin Lee's avatar
Soomin Lee committed
13 14
    typealias MLType = VLCMLArtist

15
    var updateView: (() -> Void)?
Soomin Lee's avatar
Soomin Lee committed
16

17
    var files = [VLCMLArtist]()
Soomin Lee's avatar
Soomin Lee committed
18

19 20
    var medialibrary: VLCMediaLibraryManager

21
    var indicatorName: String = NSLocalizedString("ARTISTS", comment: "")
Soomin Lee's avatar
Soomin Lee committed
22 23

    required init(medialibrary: VLCMediaLibraryManager) {
24
        self.medialibrary = medialibrary
Soomin Lee's avatar
Soomin Lee committed
25 26 27 28 29 30 31 32 33 34
        medialibrary.addObserver(self)
        files = medialibrary.getArtists()
    }

    func append(_ item: VLCMLArtist) {
        files.append(item)
    }
}

extension ArtistModel: MediaLibraryObserver {
35 36
    func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddArtists artists: [VLCMLArtist]) {
        artists.forEach({ append($0) })
37
        updateView?()
Soomin Lee's avatar
Soomin Lee committed
38 39
    }
}