mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 00:08:21 +00:00
47 lines
1.0 KiB
Swift
47 lines
1.0 KiB
Swift
import Foundation
|
|
|
|
struct ContentItem: Identifiable {
|
|
enum ContentType: String {
|
|
case video, playlist, channel
|
|
|
|
private var sortOrder: Int {
|
|
switch self {
|
|
case .channel:
|
|
return 1
|
|
case .playlist:
|
|
return 2
|
|
default:
|
|
return 3
|
|
}
|
|
}
|
|
|
|
static func < (lhs: ContentType, rhs: ContentType) -> Bool {
|
|
lhs.sortOrder < rhs.sortOrder
|
|
}
|
|
}
|
|
|
|
var video: Video!
|
|
var playlist: ChannelPlaylist!
|
|
var channel: Channel!
|
|
|
|
var id: String = UUID().uuidString
|
|
|
|
static func array(of videos: [Video]) -> [ContentItem] {
|
|
videos.map { ContentItem(video: $0) }
|
|
}
|
|
|
|
static func < (lhs: ContentItem, rhs: ContentItem) -> Bool {
|
|
lhs.contentType < rhs.contentType
|
|
}
|
|
|
|
var contentType: ContentType {
|
|
if !playlist.isNil {
|
|
return .playlist
|
|
} else if !channel.isNil {
|
|
return .channel
|
|
}
|
|
|
|
return .video
|
|
}
|
|
}
|