mirror of
https://github.com/yattee/yattee.git
synced 2025-11-25 18:58:21 +00:00
Initial functionality of player items queue
Fix environment objects Hide video player placeholder on tvOS Queue improvements
This commit is contained in:
@@ -20,6 +20,22 @@ struct ChannelVideosView: View {
|
||||
@Namespace private var focusNamespace
|
||||
|
||||
var body: some View {
|
||||
#if os(iOS)
|
||||
if inNavigationView {
|
||||
content
|
||||
} else {
|
||||
PlayerControlsView {
|
||||
content
|
||||
}
|
||||
}
|
||||
#else
|
||||
PlayerControlsView {
|
||||
content
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
var content: some View {
|
||||
VStack {
|
||||
#if os(tvOS)
|
||||
HStack {
|
||||
|
||||
109
Shared/Views/PlayerControlsView.swift
Normal file
109
Shared/Views/PlayerControlsView.swift
Normal file
@@ -0,0 +1,109 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
struct PlayerControlsView<Content: View>: View {
|
||||
let content: Content
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
@EnvironmentObject<PlayerModel> private var model
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
|
||||
init(@ViewBuilder content: @escaping () -> Content) {
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .bottomLeading) {
|
||||
content
|
||||
#if !os(tvOS)
|
||||
.frame(minHeight: 0, maxHeight: .infinity)
|
||||
.padding(.bottom, 50)
|
||||
#endif
|
||||
|
||||
#if !os(tvOS)
|
||||
controls
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private var controls: some View {
|
||||
HStack {
|
||||
Button(action: {
|
||||
model.presentingPlayer.toggle()
|
||||
}) {
|
||||
HStack {
|
||||
if let item = model.currentItem {
|
||||
HStack(spacing: 3) {
|
||||
Text(item.video.title)
|
||||
.fontWeight(.bold)
|
||||
.foregroundColor(.accentColor)
|
||||
.lineLimit(1)
|
||||
|
||||
Text("— \(item.video.author)")
|
||||
.fontWeight(.semibold)
|
||||
.foregroundColor(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
} else {
|
||||
Text("Not playing")
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.padding(.vertical, 20)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
Group {
|
||||
if model.isPlaying {
|
||||
Button(action: {
|
||||
model.pause()
|
||||
}) {
|
||||
Label("Pause", systemImage: "pause.fill")
|
||||
}
|
||||
} else {
|
||||
Button(action: {
|
||||
model.play()
|
||||
}) {
|
||||
Label("Play", systemImage: "play.fill")
|
||||
}
|
||||
.disabled(model.player.currentItem == nil)
|
||||
}
|
||||
}
|
||||
.frame(minWidth: 30)
|
||||
.scaleEffect(1.7)
|
||||
#if !os(tvOS)
|
||||
.keyboardShortcut("p")
|
||||
#endif
|
||||
|
||||
Button(action: { model.advanceToNextItem() }) {
|
||||
Label("Next", systemImage: "forward.fill")
|
||||
}
|
||||
.disabled(model.queue.isEmpty)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.labelStyle(.iconOnly)
|
||||
.padding(.horizontal)
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
.padding(.vertical, 0)
|
||||
.background(.ultraThinMaterial)
|
||||
.borderTop(height: 0.4, color: Color("PlayerControlsBorderColor"))
|
||||
.borderBottom(height: navigationStyle == .sidebar ? 0 : 0.4, color: Color("PlayerControlsBorderColor"))
|
||||
#if !os(tvOS)
|
||||
.onSwipeGesture(up: {
|
||||
model.presentingPlayer = true
|
||||
})
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
struct PlayerControlsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PlayerControlsView {
|
||||
VStack {
|
||||
Spacer()
|
||||
Text("Hello")
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,11 @@ struct PlaylistVideosView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VideosCellsVertical(videos: playlist.videos)
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("\(playlist.title) Playlist")
|
||||
#endif
|
||||
PlayerControlsView {
|
||||
VideosCellsVertical(videos: playlist.videos)
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("\(playlist.title) Playlist")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,15 @@ struct PopularView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VideosCellsVertical(videos: store.collection)
|
||||
.onAppear {
|
||||
resource.addObserver(store)
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Popular")
|
||||
#endif
|
||||
PlayerControlsView {
|
||||
VideosCellsVertical(videos: store.collection)
|
||||
.onAppear {
|
||||
resource.addObserver(store)
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Popular")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,29 +30,31 @@ struct SearchView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if showRecentQueries {
|
||||
recentQueries
|
||||
} else {
|
||||
#if os(tvOS)
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
filtersHorizontalStack
|
||||
PlayerControlsView {
|
||||
VStack {
|
||||
if showRecentQueries {
|
||||
recentQueries
|
||||
} else {
|
||||
#if os(tvOS)
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
filtersHorizontalStack
|
||||
|
||||
VideosCellsHorizontal(videos: state.store.collection)
|
||||
VideosCellsHorizontal(videos: state.store.collection)
|
||||
}
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
#else
|
||||
VideosCellsVertical(videos: state.store.collection)
|
||||
#endif
|
||||
|
||||
if noResults {
|
||||
Text("No results")
|
||||
|
||||
if searchFiltersActive {
|
||||
Button("Reset search filters", action: resetFilters)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
#else
|
||||
VideosCellsVertical(videos: state.store.collection)
|
||||
#endif
|
||||
|
||||
if noResults {
|
||||
Text("No results")
|
||||
|
||||
if searchFiltersActive {
|
||||
Button("Reset search filters", action: resetFilters)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ struct SignInRequiredView<Content: View>: View {
|
||||
openSettingsButton
|
||||
#endif
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: .infinity, alignment: .center)
|
||||
}
|
||||
|
||||
var openSettingsButton: some View {
|
||||
@@ -74,9 +75,12 @@ struct SignInRequiredView<Content: View>: View {
|
||||
|
||||
struct SignInRequiredView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SignInRequiredView(title: "Subscriptions") {
|
||||
Text("Only when signed in")
|
||||
PlayerControlsView {
|
||||
SignInRequiredView(title: "Subscriptions") {
|
||||
Text("Only when signed in")
|
||||
}
|
||||
}
|
||||
.environmentObject(PlayerModel())
|
||||
.environmentObject(InvidiousAPI())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,17 +11,19 @@ struct SubscriptionsView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
SignInRequiredView(title: "Subscriptions") {
|
||||
VideosCellsVertical(videos: store.collection)
|
||||
.onAppear {
|
||||
loadResources()
|
||||
}
|
||||
.onChange(of: api.account) { _ in
|
||||
loadResources(force: true)
|
||||
}
|
||||
.onChange(of: feed) { _ in
|
||||
loadResources(force: true)
|
||||
}
|
||||
PlayerControlsView {
|
||||
SignInRequiredView(title: "Subscriptions") {
|
||||
VideosCellsVertical(videos: store.collection)
|
||||
.onAppear {
|
||||
loadResources()
|
||||
}
|
||||
.onChange(of: api.account) { _ in
|
||||
loadResources(force: true)
|
||||
}
|
||||
.onChange(of: feed) { _ in
|
||||
loadResources(force: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
.refreshable {
|
||||
loadResources(force: true)
|
||||
|
||||
@@ -2,26 +2,72 @@ import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideoContextMenuView: View {
|
||||
let video: Video
|
||||
|
||||
@Binding var playerNavigationLinkActive: Bool
|
||||
|
||||
@Environment(\.inNavigationView) private var inNavigationView
|
||||
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
@EnvironmentObject<PlaylistsModel> private var playlists
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
|
||||
let video: Video
|
||||
|
||||
var body: some View {
|
||||
openChannelButton
|
||||
|
||||
subscriptionButton
|
||||
|
||||
if navigation.tabSelection != .playlists {
|
||||
addToPlaylistButton
|
||||
} else if let playlist = playlists.currentPlaylist {
|
||||
removeFromPlaylistButton(playlistID: playlist.id)
|
||||
Section {
|
||||
playNowButton
|
||||
}
|
||||
Section {
|
||||
playNextButton
|
||||
addToQueueButton
|
||||
}
|
||||
|
||||
if case let .playlist(id) = navigation.tabSelection {
|
||||
removeFromPlaylistButton(playlistID: id)
|
||||
Section {
|
||||
openChannelButton
|
||||
subscriptionButton
|
||||
}
|
||||
|
||||
Section {
|
||||
if navigation.tabSelection != .playlists {
|
||||
addToPlaylistButton
|
||||
} else if let playlist = playlists.currentPlaylist {
|
||||
removeFromPlaylistButton(playlistID: playlist.id)
|
||||
}
|
||||
|
||||
if case let .playlist(id) = navigation.tabSelection {
|
||||
removeFromPlaylistButton(playlistID: id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var playNowButton: some View {
|
||||
Button {
|
||||
player.playNow(video)
|
||||
|
||||
if inNavigationView {
|
||||
playerNavigationLinkActive = true
|
||||
} else {
|
||||
player.presentPlayer()
|
||||
}
|
||||
} label: {
|
||||
Label("Play Now", systemImage: "play")
|
||||
}
|
||||
}
|
||||
|
||||
var playNextButton: some View {
|
||||
Button {
|
||||
player.playNext(video)
|
||||
} label: {
|
||||
Label("Play Next", systemImage: "text.insert")
|
||||
}
|
||||
}
|
||||
|
||||
var addToQueueButton: some View {
|
||||
Button {
|
||||
player.enqueueVideo(video)
|
||||
} label: {
|
||||
Label("Play Last", systemImage: "text.append")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user