2021-06-28 15:27:53 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoContextMenuView: View {
|
2021-10-05 20:20:09 +00:00
|
|
|
let video: Video
|
|
|
|
|
|
|
|
@Binding var playerNavigationLinkActive: Bool
|
|
|
|
|
|
|
|
@Environment(\.inNavigationView) private var inNavigationView
|
2021-10-28 17:14:55 +00:00
|
|
|
@Environment(\.inChannelView) private var inChannelView
|
2021-10-21 23:29:10 +00:00
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
2021-10-24 21:36:24 +00:00
|
|
|
@Environment(\.currentPlaylistID) private var playlistID
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
2021-09-25 08:18:22 +00:00
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
2021-10-05 20:20:09 +00:00
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
2021-09-28 18:06:05 +00:00
|
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
2021-09-25 12:17:58 +00:00
|
|
|
@EnvironmentObject<RecentsModel> private var recents
|
2021-09-25 08:18:22 +00:00
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
2021-06-28 15:27:53 +00:00
|
|
|
|
|
|
|
var body: some View {
|
2021-10-05 20:20:09 +00:00
|
|
|
Section {
|
|
|
|
playNowButton
|
|
|
|
}
|
2021-10-24 21:36:24 +00:00
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
Section {
|
|
|
|
playNextButton
|
|
|
|
addToQueueButton
|
|
|
|
}
|
|
|
|
|
2021-10-28 17:14:55 +00:00
|
|
|
if !inChannelView {
|
|
|
|
Section {
|
|
|
|
openChannelButton
|
2021-10-24 21:36:24 +00:00
|
|
|
|
2021-10-28 17:14:55 +00:00
|
|
|
if accounts.app.supportsSubscriptions {
|
|
|
|
subscriptionButton
|
|
|
|
}
|
2021-10-20 22:21:50 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
if accounts.app.supportsUserPlaylists {
|
|
|
|
Section {
|
2021-10-24 21:36:24 +00:00
|
|
|
addToPlaylistButton
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2021-10-24 21:36:24 +00:00
|
|
|
if let id = navigation.tabSelection?.playlistID ?? playlistID {
|
2021-10-20 22:21:50 +00:00
|
|
|
removeFromPlaylistButton(playlistID: id)
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-19 21:27:04 +00:00
|
|
|
|
|
|
|
#if os(tvOS)
|
|
|
|
Button("Cancel", role: .cancel) {}
|
|
|
|
#endif
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-24 21:36:24 +00:00
|
|
|
private var playNowButton: some View {
|
2021-10-05 20:20:09 +00:00
|
|
|
Button {
|
|
|
|
player.playNow(video)
|
2021-08-25 22:12:59 +00:00
|
|
|
|
2021-10-28 17:14:55 +00:00
|
|
|
guard !player.playingInPictureInPicture else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
if inNavigationView {
|
|
|
|
playerNavigationLinkActive = true
|
|
|
|
} else {
|
|
|
|
player.presentPlayer()
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("Play Now", systemImage: "play")
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 22:39:18 +00:00
|
|
|
|
2021-10-24 21:36:24 +00:00
|
|
|
private var playNextButton: some View {
|
2021-10-05 20:20:09 +00:00
|
|
|
Button {
|
|
|
|
player.playNext(video)
|
|
|
|
} label: {
|
|
|
|
Label("Play Next", systemImage: "text.insert")
|
2021-09-28 23:01:49 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-09-28 18:06:05 +00:00
|
|
|
|
2021-10-28 17:14:55 +00:00
|
|
|
private var isShowingChannelButton: Bool {
|
|
|
|
if case .channel = navigation.tabSelection {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return !inChannelView
|
|
|
|
}
|
|
|
|
|
2021-10-24 21:36:24 +00:00
|
|
|
private var addToQueueButton: some View {
|
2021-10-05 20:20:09 +00:00
|
|
|
Button {
|
|
|
|
player.enqueueVideo(video)
|
|
|
|
} label: {
|
|
|
|
Label("Play Last", systemImage: "text.append")
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-10-24 21:36:24 +00:00
|
|
|
private var openChannelButton: some View {
|
2021-09-28 23:01:49 +00:00
|
|
|
Button {
|
2021-09-19 11:06:54 +00:00
|
|
|
let recent = RecentItem(from: video.channel)
|
2021-09-28 18:06:05 +00:00
|
|
|
recents.add(recent)
|
2021-10-22 23:04:03 +00:00
|
|
|
navigation.presentingChannel = true
|
2021-10-21 23:29:10 +00:00
|
|
|
|
|
|
|
if navigationStyle == .sidebar {
|
|
|
|
navigation.sidebarSectionChanged.toggle()
|
|
|
|
navigation.tabSelection = .recentlyOpened(recent.tag)
|
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
} label: {
|
|
|
|
Label("\(video.author) Channel", systemImage: "rectangle.stack.fill.badge.person.crop")
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-24 21:36:24 +00:00
|
|
|
private var subscriptionButton: some View {
|
2021-08-25 22:12:59 +00:00
|
|
|
Group {
|
2021-08-31 21:17:50 +00:00
|
|
|
if subscriptions.isSubscribing(video.channel.id) {
|
2021-11-28 14:37:55 +00:00
|
|
|
Button {
|
2021-08-31 21:17:50 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
subscriptions.unsubscribe(video.channel.id)
|
|
|
|
#else
|
2021-09-25 08:18:22 +00:00
|
|
|
navigation.presentUnsubscribeAlert(video.channel)
|
2021-08-31 21:17:50 +00:00
|
|
|
#endif
|
2021-09-28 23:01:49 +00:00
|
|
|
} label: {
|
|
|
|
Label("Unsubscribe", systemImage: "xmark.circle")
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-09-28 23:01:49 +00:00
|
|
|
Button {
|
2021-08-31 21:17:50 +00:00
|
|
|
subscriptions.subscribe(video.channel.id) {
|
2021-09-25 08:18:22 +00:00
|
|
|
navigation.sidebarSectionChanged.toggle()
|
2021-08-31 21:17:50 +00:00
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
} label: {
|
|
|
|
Label("Subscribe", systemImage: "star.circle")
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-09 14:53:53 +00:00
|
|
|
|
2021-10-24 21:36:24 +00:00
|
|
|
private var addToPlaylistButton: some View {
|
2021-09-28 23:01:49 +00:00
|
|
|
Button {
|
2021-09-28 18:06:05 +00:00
|
|
|
navigation.presentAddToPlaylist(video)
|
2021-09-28 23:01:49 +00:00
|
|
|
} label: {
|
|
|
|
Label("Add to playlist...", systemImage: "text.badge.plus")
|
2021-07-09 14:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 18:06:05 +00:00
|
|
|
func removeFromPlaylistButton(playlistID: String) -> some View {
|
2021-11-28 14:37:55 +00:00
|
|
|
Button {
|
2021-10-24 21:36:24 +00:00
|
|
|
playlists.removeVideo(videoIndexID: video.indexID!, playlistID: playlistID)
|
2021-09-28 23:01:49 +00:00
|
|
|
} label: {
|
|
|
|
Label("Remove from playlist", systemImage: "text.badge.minus")
|
2021-07-09 14:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|