MediaLibraryBaseModel.swift 1.75 KB
Newer Older
Soomin Lee's avatar
Soomin Lee committed
1 2 3 4 5 6 7 8 9 10 11
/*****************************************************************************
 * MediaLibraryBaseModel.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 13 14 15 16 17 18 19 20
// Expose a "shadow" version without associatedType in order to use it as a type
protocol MediaLibraryBaseModel {
    init(medialibrary: VLCMediaLibraryManager)

    var anyfiles: [VLCMLObject] { get }

    var updateView: (() -> Void)? { get set }

    var indicatorName: String { get }
21
    var cellType: BaseCollectionViewCell.Type { get }
22 23

    func append(_ item: VLCMLObject)
Soomin Lee's avatar
Soomin Lee committed
24
    func delete(_ items: [VLCMLObject])
Soomin Lee's avatar
Soomin Lee committed
25
    func sort(by criteria: VLCMLSortingCriteria)
26 27
}

28
protocol MLBaseModel: AnyObject, MediaLibraryBaseModel {
Soomin Lee's avatar
Soomin Lee committed
29 30
    associatedtype MLType where MLType: VLCMLObject

31 32
    init(medialibrary: VLCMediaLibraryManager)

Soomin Lee's avatar
Soomin Lee committed
33
    var files: [MLType] { get set }
34

35 36
    var medialibrary: VLCMediaLibraryManager { get }

37
    var updateView: (() -> Void)? { get set }
Soomin Lee's avatar
Soomin Lee committed
38 39 40 41

    var indicatorName: String { get }

    func append(_ item: MLType)
Soomin Lee's avatar
Soomin Lee committed
42 43
    // FIXME: Ideally items should be MLType but Swift isn't happy so it will always fail
    func delete(_ items: [VLCMLObject])
Soomin Lee's avatar
Soomin Lee committed
44
    func sort(by criteria: VLCMLSortingCriteria)
Soomin Lee's avatar
Soomin Lee committed
45
}
46 47

extension MLBaseModel {
48

49 50 51 52 53 54 55 56
    var anyfiles: [VLCMLObject] {
        return files
    }

    func append(_ item: VLCMLObject) {
        fatalError()
    }

Soomin Lee's avatar
Soomin Lee committed
57 58 59 60
    func delete(_ items: [VLCMLObject]) {
        fatalError()
    }

Soomin Lee's avatar
Soomin Lee committed
61 62 63
    func sort(by criteria: VLCMLSortingCriteria) {
        fatalError()
    }
64
}
65 66 67 68 69 70

protocol EditableMLModel {

    func editCellType() -> BaseCollectionViewCell.Type

}