1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Shared/Views/VideoContextMenuView.swift

153 lines
4.3 KiB
Swift
Raw Normal View History

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