AlbumModel.swift 1.18 KB
Newer Older
Soomin Lee's avatar
Soomin Lee committed
1 2 3 4 5 6 7 8 9 10 11
/*****************************************************************************
 * AlbumModel.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 AlbumModel: MLBaseModel {
Soomin Lee's avatar
Soomin Lee committed
13 14
    typealias MLType = VLCMLAlbum

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

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

19 20
    var medialibrary: VLCMediaLibraryManager

21
    var indicatorName: String = NSLocalizedString("ALBUMS", 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
        medialibrary.addObserver(self)
        files = medialibrary.getAlbums()
    }

    func append(_ item: VLCMLAlbum) {
        files.append(item)
    }
Soomin Lee's avatar
Soomin Lee committed
32 33 34 35

    func delete(_ items: [VLCMLObject]) {
        preconditionFailure("AlbumModel: Cannot delete album")
    }
Soomin Lee's avatar
Soomin Lee committed
36 37 38
}

extension AlbumModel: MediaLibraryObserver {
39 40
    func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddAlbums albums: [VLCMLAlbum]) {
        albums.forEach({ append($0) })
41
        updateView?()
Soomin Lee's avatar
Soomin Lee committed
42 43
    }
}