1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-12 21:30:32 +05:30
yattee/Model/ContentItem.swift

66 lines
1.5 KiB
Swift
Raw Permalink Normal View History

import Foundation
struct ContentItem: Identifiable {
enum ContentType: String {
2022-03-27 16:19:57 +05:30
case video, playlist, channel, placeholder
private var sortOrder: Int {
switch self {
case .channel:
return 1
2021-10-23 04:34:03 +05:30
case .playlist:
return 2
default:
return 3
}
}
2023-06-17 17:39:51 +05:30
static func < (lhs: Self, rhs: Self) -> Bool {
lhs.sortOrder < rhs.sortOrder
}
}
2022-12-14 21:50:24 +05:30
static var placeholders: [Self] {
(0 ..< 9).map { i in .init(id: String(i)) }
}
var video: Video!
2021-10-23 04:34:03 +05:30
var playlist: ChannelPlaylist!
var channel: Channel!
2021-10-23 14:04:37 +05:30
var id: String = UUID().uuidString
2023-06-17 17:39:51 +05:30
static func array(of videos: [Video]) -> [Self] {
2023-04-22 18:38:33 +05:30
videos.map { Self(video: $0) }
}
2023-06-17 17:39:51 +05:30
static func array(of playlists: [ChannelPlaylist]) -> [Self] {
2023-04-22 18:38:33 +05:30
playlists.map { Self(playlist: $0) }
2022-11-27 16:12:16 +05:30
}
2023-06-17 17:39:51 +05:30
static func array(of channels: [Channel]) -> [Self] {
2023-04-22 18:38:33 +05:30
channels.map { Self(channel: $0) }
2022-11-27 16:12:16 +05:30
}
2023-06-17 17:39:51 +05:30
static func < (lhs: Self, rhs: Self) -> Bool {
lhs.contentType < rhs.contentType
}
var contentType: ContentType {
2022-03-27 16:19:57 +05:30
video.isNil ? (channel.isNil ? (playlist.isNil ? .placeholder : .playlist) : .channel) : .video
}
2022-12-17 01:07:05 +05:30
var cacheKey: String {
switch contentType {
case .video:
return video.cacheKey
case .playlist:
return playlist.cacheKey
case .channel:
return channel.cacheKey
case .placeholder:
return id
}
}
}