2023-05-23 16:48:39 +00:00
|
|
|
import Defaults
|
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
|
2023-05-23 16:54:53 +00:00
|
|
|
@Default(.hideShorts) private var hideShorts
|
2023-05-23 16:48:39 +00:00
|
|
|
@Default(.hideWatched) private var hideWatched
|
|
|
|
|
|
|
|
@FetchRequest private var watchRequest: FetchedResults<Watch>
|
|
|
|
|
|
|
|
init(item: ContentItem) {
|
|
|
|
self.item = item
|
|
|
|
if item.contentType == .video, let video = item.video {
|
|
|
|
_watchRequest = video.watchFetchRequest
|
|
|
|
} else {
|
|
|
|
_watchRequest = Video.fixture.watchFetchRequest
|
|
|
|
}
|
|
|
|
}
|
2021-10-21 23:29:10 +00:00
|
|
|
|
2023-02-25 15:42:18 +00:00
|
|
|
@ViewBuilder var body: some View {
|
|
|
|
if itemVisible {
|
|
|
|
Group {
|
|
|
|
switch item.contentType {
|
|
|
|
case .video:
|
|
|
|
videoItem(item.video)
|
|
|
|
case .channel:
|
|
|
|
channelItem(item.channel)
|
|
|
|
case .playlist:
|
|
|
|
playlistItem(item.playlist)
|
|
|
|
default:
|
|
|
|
placeholderItem()
|
|
|
|
}
|
2021-10-21 23:29:10 +00:00
|
|
|
}
|
2023-02-25 15:42:18 +00:00
|
|
|
.id(item.cacheKey)
|
2021-10-21 23:29:10 +00:00
|
|
|
}
|
2023-02-25 15:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var itemVisible: Bool {
|
2023-05-23 16:48:39 +00:00
|
|
|
if hideWatched, watch?.finished ?? false {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-02-25 15:42:18 +00:00
|
|
|
guard hideShorts, item.contentType == .video, let video = item.video else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return !video.short
|
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 {
|
2023-05-23 16:48:39 +00:00
|
|
|
VideoCell(video: video, watch: watch)
|
2022-12-13 10:40:08 +00:00
|
|
|
} else {
|
2022-12-18 23:10:05 +00:00
|
|
|
let item = PlayerQueueItem(video)
|
2023-05-23 16:48:39 +00:00
|
|
|
PlayerQueueRow(item: item, watch: watch)
|
2022-12-13 10:40:08 +00:00
|
|
|
.contextMenu {
|
|
|
|
VideoContextMenuView(video: video)
|
|
|
|
}
|
2023-05-24 09:11:18 +00:00
|
|
|
.id(item.contentItem.cacheKey)
|
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
|
|
|
|
}
|
|
|
|
}
|
2023-05-23 16:48:39 +00:00
|
|
|
|
|
|
|
private var watch: Watch? {
|
|
|
|
watchRequest.first
|
|
|
|
}
|
2021-10-21 23:29:10 +00:00
|
|
|
}
|