2022-11-13 23:22:15 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoActions: View {
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var accounts = AccountsModel.shared
|
|
|
|
var navigation = NavigationModel.shared
|
2022-12-11 20:45:42 +05:30
|
|
|
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2022-11-13 23:22:15 +05:30
|
|
|
|
|
|
|
var video: Video?
|
|
|
|
|
2022-11-19 03:34:49 +05:30
|
|
|
@Default(.playerActionsButtonLabelStyle) private var playerActionsButtonLabelStyle
|
|
|
|
|
2022-11-13 23:22:15 +05:30
|
|
|
var body: some View {
|
|
|
|
HStack {
|
|
|
|
if let video {
|
2022-11-14 04:10:18 +05:30
|
|
|
#if !os(tvOS)
|
|
|
|
if !video.isLocal || video.localStreamIsRemoteURL {
|
|
|
|
ShareButton(contentItem: .init(video: video)) {
|
|
|
|
actionButton("Share", systemImage: "square.and.arrow.up")
|
|
|
|
}
|
2022-11-13 23:22:15 +05:30
|
|
|
|
2022-11-14 04:10:18 +05:30
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
#endif
|
2022-11-14 02:25:19 +05:30
|
|
|
|
|
|
|
if !video.isLocal {
|
|
|
|
if accounts.signedIn, accounts.app.supportsUserPlaylists {
|
|
|
|
actionButton("Add", systemImage: "text.badge.plus") {
|
|
|
|
navigation.presentAddToPlaylist(video)
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
2022-11-14 02:25:19 +05:30
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
if accounts.signedIn, accounts.app.supportsSubscriptions {
|
|
|
|
if subscriptions.isSubscribing(video.channel.id) {
|
|
|
|
actionButton("Unsubscribe", systemImage: "xmark.circle") {
|
|
|
|
#if os(tvOS)
|
|
|
|
subscriptions.unsubscribe(video.channel.id)
|
|
|
|
#else
|
|
|
|
navigation.presentUnsubscribeAlert(video.channel, subscriptions: subscriptions)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionButton("Subscribe", systemImage: "star.circle") {
|
|
|
|
subscriptions.subscribe(video.channel.id) {
|
|
|
|
navigation.sidebarSectionChanged.toggle()
|
|
|
|
}
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
|
|
|
}
|
2022-11-14 02:25:19 +05:30
|
|
|
Spacer()
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 02:25:19 +05:30
|
|
|
|
|
|
|
if player.currentItem == nil {
|
|
|
|
Spacer()
|
|
|
|
}
|
2022-11-13 23:22:15 +05:30
|
|
|
|
|
|
|
actionButton("Hide", systemImage: "chevron.down") {
|
|
|
|
player.hide(animate: true)
|
|
|
|
}
|
2022-11-14 02:25:19 +05:30
|
|
|
|
2022-11-13 23:22:15 +05:30
|
|
|
if player.currentItem != nil {
|
|
|
|
Spacer()
|
|
|
|
actionButton("Close", systemImage: "xmark") {
|
|
|
|
player.closeCurrentItem()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
|
|
|
.multilineTextAlignment(.center)
|
|
|
|
.frame(maxWidth: .infinity)
|
|
|
|
.frame(height: 50)
|
2022-11-19 02:57:13 +05:30
|
|
|
.borderBottom(height: 0.5, color: Color("ControlsBorderColor"))
|
2022-11-13 23:22:15 +05:30
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
}
|
|
|
|
|
|
|
|
func actionButton(
|
|
|
|
_ name: String,
|
|
|
|
systemImage: String,
|
|
|
|
action: @escaping () -> Void = {}
|
|
|
|
) -> some View {
|
|
|
|
Button(action: action) {
|
|
|
|
VStack(spacing: 3) {
|
|
|
|
Image(systemName: systemImage)
|
|
|
|
.frame(width: 20, height: 20)
|
2022-11-19 03:34:49 +05:30
|
|
|
if playerActionsButtonLabelStyle.text {
|
2022-11-19 04:36:13 +05:30
|
|
|
Text(name.localized())
|
2022-11-19 03:34:49 +05:30
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.font(.caption2)
|
|
|
|
.allowsTightening(true)
|
|
|
|
}
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
2022-11-19 03:34:49 +05:30
|
|
|
.padding(.horizontal, playerActionsButtonLabelStyle.text ? 6 : 12)
|
|
|
|
.padding(.vertical, playerActionsButtonLabelStyle.text ? 5 : 10)
|
2022-11-13 23:22:15 +05:30
|
|
|
.contentShape(Rectangle())
|
|
|
|
}
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
.accessibilityLabel(Text(name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct VideoActions_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
VideoActions()
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|