2021-10-21 23:29:10 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ContentItemView: View {
|
|
|
|
let item: ContentItem
|
2022-12-12 00:18:29 +00:00
|
|
|
@Environment(\.listingStyle) private var listingStyle
|
2022-12-18 23:10:05 +00:00
|
|
|
@Environment(\.noListingDividers) private var noListingDividers
|
2021-10-21 23:29:10 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Group {
|
|
|
|
switch item.contentType {
|
2022-08-13 14:46:45 +00:00
|
|
|
case .video:
|
2022-12-13 10:40:08 +00:00
|
|
|
videoItem(item.video)
|
2021-10-21 23:29:10 +00:00
|
|
|
case .channel:
|
2022-12-13 10:40:08 +00:00
|
|
|
channelItem(item.channel)
|
|
|
|
case .playlist:
|
|
|
|
playlistItem(item.playlist)
|
2022-03-27 10:49:57 +00:00
|
|
|
default:
|
2022-12-13 10:40:08 +00:00
|
|
|
placeholderItem()
|
2021-10-21 23:29:10 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-16 19:37:05 +00:00
|
|
|
.id(item.cacheKey)
|
2021-10-21 23:29:10 +00:00
|
|
|
}
|
2022-12-13 10:40:08 +00:00
|
|
|
|
|
|
|
@ViewBuilder func videoItem(_ video: Video) -> some View {
|
|
|
|
if listingStyle == .cells {
|
|
|
|
VideoCell(video: video)
|
|
|
|
} else {
|
2022-12-18 23:10:05 +00:00
|
|
|
let item = PlayerQueueItem(video)
|
|
|
|
PlayerQueueRow(item: item)
|
2022-12-13 10:40:08 +00:00
|
|
|
.contextMenu {
|
|
|
|
VideoContextMenuView(video: video)
|
|
|
|
}
|
2022-12-18 23:10:05 +00:00
|
|
|
.id(item.id)
|
2022-12-13 10:40:08 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 30)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
Divider()
|
2022-12-18 23:10:05 +00:00
|
|
|
.opacity(noListingDividers ? 0 : 1)
|
2022-12-13 10:40:08 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder func playlistItem(_ playlist: ChannelPlaylist) -> some View {
|
|
|
|
if listingStyle == .cells {
|
|
|
|
ChannelPlaylistCell(playlist: playlist)
|
|
|
|
} else {
|
|
|
|
ChannelPlaylistListItem(playlist: playlist)
|
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 30)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
Divider()
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder func channelItem(_ channel: Channel) -> some View {
|
|
|
|
if listingStyle == .cells {
|
|
|
|
ChannelCell(channel: channel)
|
|
|
|
} else {
|
|
|
|
ChannelListItem(channel: channel)
|
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 30)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
Divider()
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder func placeholderItem() -> some View {
|
|
|
|
if listingStyle == .cells {
|
|
|
|
PlaceholderCell()
|
2022-12-14 16:20:24 +00:00
|
|
|
.id(item.id)
|
2022-12-13 10:40:08 +00:00
|
|
|
} else {
|
|
|
|
PlaceholderListItem()
|
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 30)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
Divider()
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2021-10-21 23:29:10 +00:00
|
|
|
}
|