1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 23:00:32 +05:30
yattee/Shared/Views/ContentItemView.swift

92 lines
2.3 KiB
Swift
Raw Normal View History

import Foundation
import SwiftUI
struct ContentItemView: View {
let item: ContentItem
2022-12-12 05:48:29 +05:30
@Environment(\.listingStyle) private var listingStyle
2022-12-19 04:40:05 +05:30
@Environment(\.noListingDividers) private var noListingDividers
var body: some View {
Group {
switch item.contentType {
2022-08-13 20:16:45 +05:30
case .video:
videoItem(item.video)
case .channel:
channelItem(item.channel)
case .playlist:
playlistItem(item.playlist)
2022-03-27 16:19:57 +05:30
default:
placeholderItem()
}
}
2022-12-17 01:07:05 +05:30
.id(item.cacheKey)
}
@ViewBuilder func videoItem(_ video: Video) -> some View {
if listingStyle == .cells {
VideoCell(video: video)
} else {
2022-12-19 04:40:05 +05:30
let item = PlayerQueueItem(video)
PlayerQueueRow(item: item)
.contextMenu {
VideoContextMenuView(video: video)
}
2022-12-19 04:40:05 +05:30
.id(item.id)
#if os(tvOS)
.padding(.horizontal, 30)
#endif
#if !os(tvOS)
Divider()
2022-12-19 04:40:05 +05:30
.opacity(noListingDividers ? 0 : 1)
#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 21:50:24 +05:30
.id(item.id)
} else {
PlaceholderListItem()
#if os(tvOS)
.padding(.horizontal, 30)
#endif
#if !os(tvOS)
Divider()
#endif
}
}
}