This commit is contained in:
Arkadiusz Fal 2022-03-27 12:50:36 +02:00
parent ae4796a4c5
commit 8770bfb56d

View File

@ -6,6 +6,7 @@ struct VideoCell: View {
private var video: Video private var video: Video
@Environment(\.inNavigationView) private var inNavigationView @Environment(\.inNavigationView) private var inNavigationView
@Environment(\.navigationStyle) private var navigationStyle
#if os(iOS) #if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass @Environment(\.verticalSizeClass) private var verticalSizeClass
@ -13,7 +14,9 @@ struct VideoCell: View {
#endif #endif
@EnvironmentObject<AccountsModel> private var accounts @EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerModel> private var player @EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<ThumbnailsModel> private var thumbnails @EnvironmentObject<ThumbnailsModel> private var thumbnails
@Default(.channelOnThumbnail) private var channelOnThumbnail @Default(.channelOnThumbnail) private var channelOnThumbnail
@ -147,9 +150,7 @@ struct VideoCell: View {
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
if !channelOnThumbnail { if !channelOnThumbnail {
Text(video.channel.name) channelButton(badge: false)
.fontWeight(.semibold)
.foregroundColor(.secondary)
} }
if additionalDetailsAvailable { if additionalDetailsAvailable {
@ -231,9 +232,7 @@ struct VideoCell: View {
.frame(minHeight: 40, alignment: .top) .frame(minHeight: 40, alignment: .top)
#endif #endif
if !channelOnThumbnail { if !channelOnThumbnail {
Text(video.channel.name) channelButton(badge: false)
.fontWeight(.semibold)
.foregroundColor(.secondary)
.padding(.top, 4) .padding(.top, 4)
.padding(.bottom, 6) .padding(.bottom, 6)
} }
@ -289,6 +288,29 @@ struct VideoCell: View {
} }
} }
private func channelButton(badge: Bool = true) -> some View {
Button {
NavigationModel.openChannel(
video.channel,
player: player,
recents: recents,
navigation: navigation,
navigationStyle: navigationStyle
)
} label: {
if badge {
DetailBadge(text: video.author, style: .prominent)
.foregroundColor(.primary)
} else {
Text(video.channel.name)
.fontWeight(.semibold)
.foregroundColor(.secondary)
}
}
.buttonStyle(.plain)
.help("\(video.channel.name) Channel")
}
private var additionalDetailsAvailable: Bool { private var additionalDetailsAvailable: Bool {
video.publishedDate != nil || video.views != 0 || video.publishedDate != nil || video.views != 0 ||
(!timeOnThumbnail && !video.length.formattedAsPlaybackTime().isNil) (!timeOnThumbnail && !video.length.formattedAsPlaybackTime().isNil)
@ -325,7 +347,7 @@ struct VideoCell: View {
Spacer() Spacer()
if channelOnThumbnail { if channelOnThumbnail {
DetailBadge(text: video.author, style: .prominent) channelButton()
} }
} }
#if os(tvOS) #if os(tvOS)
@ -415,7 +437,7 @@ struct VideoCell: View {
stoppedAt.isFinite, stoppedAt.isFinite,
let stoppedAtFormatted = stoppedAt.formattedAsPlaybackTime() let stoppedAtFormatted = stoppedAt.formattedAsPlaybackTime()
{ {
if watch?.videoDuration ?? 0 > 0 { if (watch?.videoDuration ?? 0) > 0 {
videoTime = watch!.videoDuration.formattedAsPlaybackTime() ?? "?" videoTime = watch!.videoDuration.formattedAsPlaybackTime() ?? "?"
} }
return "\(stoppedAtFormatted) / \(videoTime)" return "\(stoppedAtFormatted) / \(videoTime)"