2021-08-30 03:06:18 +05:30
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlaylistVideosView: View {
|
|
|
|
let playlist: Playlist
|
|
|
|
|
2022-01-03 00:29:57 +05:30
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
2022-05-22 03:59:51 +05:30
|
|
|
@EnvironmentObject<PlaylistsModel> private var model
|
2022-01-03 00:29:57 +05:30
|
|
|
|
2022-04-10 20:37:10 +05:30
|
|
|
@StateObject private var store = Store<ChannelPlaylist>()
|
|
|
|
|
2022-01-03 00:29:57 +05:30
|
|
|
var contentItems: [ContentItem] {
|
2022-05-22 03:59:51 +05:30
|
|
|
var videos = playlist.videos
|
|
|
|
|
|
|
|
if videos.isEmpty {
|
|
|
|
videos = store.item?.videos ?? []
|
|
|
|
if !player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
|
|
|
var i = 0
|
|
|
|
|
|
|
|
for index in videos.indices {
|
|
|
|
var video = videos[index]
|
|
|
|
video.indexID = "\(i)"
|
|
|
|
i += 1
|
|
|
|
videos[index] = video
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ContentItem.array(of: videos)
|
2022-04-10 20:37:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private var resource: Resource? {
|
|
|
|
let resource = player.accounts.api.playlist(playlist.id)
|
|
|
|
resource?.addObserver(store)
|
|
|
|
|
|
|
|
return resource
|
2021-10-22 04:59:10 +05:30
|
|
|
}
|
|
|
|
|
2022-01-03 00:29:57 +05:30
|
|
|
var videos: [Video] {
|
|
|
|
contentItems.compactMap(\.video)
|
|
|
|
}
|
|
|
|
|
2021-08-30 03:06:18 +05:30
|
|
|
init(_ playlist: Playlist) {
|
|
|
|
self.playlist = playlist
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
2022-02-17 01:53:11 +05:30
|
|
|
BrowserPlayerControls {
|
2022-01-03 00:29:57 +05:30
|
|
|
VerticalCells(items: contentItems)
|
2022-04-10 20:37:10 +05:30
|
|
|
.onAppear {
|
|
|
|
if !player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
2022-05-22 03:59:51 +05:30
|
|
|
resource?.load()
|
2022-04-10 20:37:10 +05:30
|
|
|
}
|
|
|
|
}
|
2022-05-22 03:59:51 +05:30
|
|
|
.onChange(of: model.reloadPlaylists) { _ in
|
|
|
|
resource?.load()
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
#if !os(tvOS)
|
|
|
|
.navigationTitle("\(playlist.title) Playlist")
|
|
|
|
#endif
|
|
|
|
}
|
2021-11-02 03:26:18 +05:30
|
|
|
.toolbar {
|
2022-01-03 00:29:57 +05:30
|
|
|
ToolbarItem(placement: playlistButtonsPlacement) {
|
|
|
|
HStack {
|
|
|
|
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title)))
|
|
|
|
|
|
|
|
Button {
|
2022-07-11 03:54:56 +05:30
|
|
|
player.playbackMode = .queue
|
2022-05-29 03:11:23 +05:30
|
|
|
player.play(videos)
|
2022-01-03 00:29:57 +05:30
|
|
|
} label: {
|
|
|
|
Label("Play All", systemImage: "play")
|
|
|
|
}
|
|
|
|
}
|
2021-11-02 03:26:18 +05:30
|
|
|
}
|
|
|
|
}
|
2021-08-30 03:06:18 +05:30
|
|
|
}
|
2022-01-03 00:29:57 +05:30
|
|
|
|
|
|
|
private var playlistButtonsPlacement: ToolbarItemPlacement {
|
|
|
|
#if os(iOS)
|
|
|
|
.navigationBarTrailing
|
|
|
|
#else
|
|
|
|
.automatic
|
|
|
|
#endif
|
|
|
|
}
|
2021-08-30 03:06:18 +05:30
|
|
|
}
|