2021-10-21 23:29:10 +00:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct ContentItem: Identifiable {
|
|
|
|
enum ContentType: String {
|
2022-03-27 10:49:57 +00:00
|
|
|
case video, playlist, channel, placeholder
|
2021-10-21 23:29:10 +00:00
|
|
|
|
|
|
|
private var sortOrder: Int {
|
|
|
|
switch self {
|
|
|
|
case .channel:
|
|
|
|
return 1
|
2021-10-22 23:04:03 +00:00
|
|
|
case .playlist:
|
2021-10-21 23:29:10 +00:00
|
|
|
return 2
|
|
|
|
default:
|
|
|
|
return 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static func < (lhs: ContentType, rhs: ContentType) -> Bool {
|
|
|
|
lhs.sortOrder < rhs.sortOrder
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 16:20:24 +00:00
|
|
|
static var placeholders: [Self] {
|
|
|
|
(0 ..< 9).map { i in .init(id: String(i)) }
|
|
|
|
}
|
|
|
|
|
2021-10-21 23:29:10 +00:00
|
|
|
var video: Video!
|
2021-10-22 23:04:03 +00:00
|
|
|
var playlist: ChannelPlaylist!
|
2021-10-21 23:29:10 +00:00
|
|
|
var channel: Channel!
|
|
|
|
|
2021-10-23 08:34:37 +00:00
|
|
|
var id: String = UUID().uuidString
|
|
|
|
|
2021-10-21 23:29:10 +00:00
|
|
|
static func array(of videos: [Video]) -> [ContentItem] {
|
|
|
|
videos.map { ContentItem(video: $0) }
|
|
|
|
}
|
|
|
|
|
2022-11-27 10:42:16 +00:00
|
|
|
static func array(of playlists: [ChannelPlaylist]) -> [ContentItem] {
|
|
|
|
playlists.map { ContentItem(playlist: $0) }
|
|
|
|
}
|
|
|
|
|
|
|
|
static func array(of channels: [Channel]) -> [ContentItem] {
|
|
|
|
channels.map { ContentItem(channel: $0) }
|
|
|
|
}
|
|
|
|
|
2021-10-21 23:29:10 +00:00
|
|
|
static func < (lhs: ContentItem, rhs: ContentItem) -> Bool {
|
|
|
|
lhs.contentType < rhs.contentType
|
|
|
|
}
|
|
|
|
|
|
|
|
var contentType: ContentType {
|
2022-03-27 10:49:57 +00:00
|
|
|
video.isNil ? (channel.isNil ? (playlist.isNil ? .placeholder : .playlist) : .channel) : .video
|
2021-10-21 23:29:10 +00:00
|
|
|
}
|
|
|
|
}
|