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