mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Improve video banner and playback queue view
This commit is contained in:
parent
8a43ed9503
commit
28709a2c80
@ -26,7 +26,7 @@ final class PlaylistsModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func load(force: Bool = false, onSuccess: @escaping () -> Void = {}) {
|
func load(force: Bool = false, onSuccess: @escaping () -> Void = {}) {
|
||||||
let request = force ? resource.load() : resource.loadIfNeeded()
|
let request = force ? resource?.load() : resource?.loadIfNeeded()
|
||||||
|
|
||||||
request?
|
request?
|
||||||
.onSuccess { resource in
|
.onSuccess { resource in
|
||||||
@ -66,8 +66,8 @@ final class PlaylistsModel: ObservableObject {
|
|||||||
selectedPlaylistID = id ?? ""
|
selectedPlaylistID = id ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private var resource: Resource {
|
private var resource: Resource? {
|
||||||
accounts.api.playlists!
|
accounts.api.playlists
|
||||||
}
|
}
|
||||||
|
|
||||||
private var selectedPlaylist: Playlist? {
|
private var selectedPlaylist: Playlist? {
|
||||||
|
@ -292,7 +292,6 @@
|
|||||||
37CC3F47270CE30600608308 /* PlayerQueueItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F44270CE30600608308 /* PlayerQueueItem.swift */; };
|
37CC3F47270CE30600608308 /* PlayerQueueItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F44270CE30600608308 /* PlayerQueueItem.swift */; };
|
||||||
37CC3F4C270CFE1700608308 /* PlayerQueueView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4B270CFE1700608308 /* PlayerQueueView.swift */; };
|
37CC3F4C270CFE1700608308 /* PlayerQueueView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4B270CFE1700608308 /* PlayerQueueView.swift */; };
|
||||||
37CC3F4D270CFE1700608308 /* PlayerQueueView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4B270CFE1700608308 /* PlayerQueueView.swift */; };
|
37CC3F4D270CFE1700608308 /* PlayerQueueView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4B270CFE1700608308 /* PlayerQueueView.swift */; };
|
||||||
37CC3F4E270CFE1700608308 /* PlayerQueueView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4B270CFE1700608308 /* PlayerQueueView.swift */; };
|
|
||||||
37CC3F50270D010D00608308 /* VideoBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4F270D010D00608308 /* VideoBanner.swift */; };
|
37CC3F50270D010D00608308 /* VideoBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4F270D010D00608308 /* VideoBanner.swift */; };
|
||||||
37CC3F51270D010D00608308 /* VideoBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4F270D010D00608308 /* VideoBanner.swift */; };
|
37CC3F51270D010D00608308 /* VideoBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4F270D010D00608308 /* VideoBanner.swift */; };
|
||||||
37CC3F52270D010D00608308 /* VideoBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4F270D010D00608308 /* VideoBanner.swift */; };
|
37CC3F52270D010D00608308 /* VideoBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CC3F4F270D010D00608308 /* VideoBanner.swift */; };
|
||||||
@ -1714,7 +1713,6 @@
|
|||||||
37AAF2A226741C97007FC770 /* SubscriptionsView.swift in Sources */,
|
37AAF2A226741C97007FC770 /* SubscriptionsView.swift in Sources */,
|
||||||
37484C1B26FC837400287258 /* PlaybackSettingsView.swift in Sources */,
|
37484C1B26FC837400287258 /* PlaybackSettingsView.swift in Sources */,
|
||||||
372915E82687E3B900F5A35B /* Defaults.swift in Sources */,
|
372915E82687E3B900F5A35B /* Defaults.swift in Sources */,
|
||||||
37CC3F4E270CFE1700608308 /* PlayerQueueView.swift in Sources */,
|
|
||||||
37BAB54C269B39FD00E75ED1 /* TVNavigationView.swift in Sources */,
|
37BAB54C269B39FD00E75ED1 /* TVNavigationView.swift in Sources */,
|
||||||
3797758D2689345500DD52A8 /* Store.swift in Sources */,
|
3797758D2689345500DD52A8 /* Store.swift in Sources */,
|
||||||
37484C2F26FC844700287258 /* AccountsSettingsView.swift in Sources */,
|
37484C2F26FC844700287258 /* AccountsSettingsView.swift in Sources */,
|
||||||
|
@ -8,14 +8,21 @@ struct PlayerQueueView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
|
Group {
|
||||||
playingNext
|
playingNext
|
||||||
playedPreviously
|
playedPreviously
|
||||||
}
|
}
|
||||||
|
.padding(.vertical, 5)
|
||||||
|
.listRowInsets(EdgeInsets())
|
||||||
|
#if os(iOS)
|
||||||
|
.padding(.horizontal, 10)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
.listStyle(.inset)
|
.listStyle(.inset)
|
||||||
#elseif os(iOS)
|
#elseif os(iOS)
|
||||||
.listStyle(.insetGrouped)
|
.listStyle(.grouped)
|
||||||
#else
|
#else
|
||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
#endif
|
#endif
|
||||||
@ -44,12 +51,9 @@ struct PlayerQueueView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var playedPreviously: some View {
|
var playedPreviously: some View {
|
||||||
|
Group {
|
||||||
|
if !player.history.isEmpty {
|
||||||
Section(header: Text("Played Previously")) {
|
Section(header: Text("Played Previously")) {
|
||||||
if player.history.isEmpty {
|
|
||||||
Text("History is empty")
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
}
|
|
||||||
|
|
||||||
ForEach(player.history) { item in
|
ForEach(player.history) { item in
|
||||||
PlayerQueueRow(item: item, history: true, fullScreen: $fullScreen)
|
PlayerQueueRow(item: item, history: true, fullScreen: $fullScreen)
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
@ -64,6 +68,8 @@ struct PlayerQueueView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func removeButton(_ item: PlayerQueueItem, history: Bool) -> some View {
|
func removeButton(_ item: PlayerQueueItem, history: Bool) -> some View {
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
|
@ -6,7 +6,6 @@ final class PlayerViewController: UIViewController {
|
|||||||
var playerLoaded = false
|
var playerLoaded = false
|
||||||
var playerModel: PlayerModel!
|
var playerModel: PlayerModel!
|
||||||
var playerViewController = AVPlayerViewController()
|
var playerViewController = AVPlayerViewController()
|
||||||
var shouldResume = false
|
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
@ -73,15 +72,9 @@ extension PlayerViewController: AVPlayerViewControllerDelegate {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
func playerViewControllerWillBeginDismissalTransition(_: AVPlayerViewController) {
|
func playerViewControllerWillBeginDismissalTransition(_: AVPlayerViewController) {}
|
||||||
shouldResume = playerModel.isPlaying
|
|
||||||
}
|
|
||||||
|
|
||||||
func playerViewControllerDidEndDismissalTransition(_: AVPlayerViewController) {
|
func playerViewControllerDidEndDismissalTransition(_: AVPlayerViewController) {
|
||||||
if shouldResume {
|
|
||||||
playerModel.play()
|
|
||||||
}
|
|
||||||
|
|
||||||
dismiss(animated: false)
|
dismiss(animated: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,10 @@ struct VideoDetails: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
if video.isNil {
|
||||||
|
currentPage = .queue
|
||||||
|
}
|
||||||
|
|
||||||
guard video != nil, accounts.app.supportsSubscriptions else {
|
guard video != nil, accounts.app.supportsSubscriptions else {
|
||||||
subscribed = false
|
subscribed = false
|
||||||
return
|
return
|
||||||
@ -94,6 +98,15 @@ struct VideoDetails: View {
|
|||||||
|
|
||||||
subscribed = subscriptions.isSubscribing(video!.channel.id)
|
subscribed = subscriptions.isSubscribing(video!.channel.id)
|
||||||
}
|
}
|
||||||
|
.onChange(of: sidebarQueue) { queue in
|
||||||
|
#if !os(macOS)
|
||||||
|
if queue {
|
||||||
|
currentPage = .details
|
||||||
|
} else {
|
||||||
|
currentPage = .queue
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
.edgesIgnoringSafeArea(.horizontal)
|
.edgesIgnoringSafeArea(.horizontal)
|
||||||
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
||||||
}
|
}
|
||||||
@ -112,11 +125,6 @@ struct VideoDetails: View {
|
|||||||
} else {
|
} else {
|
||||||
Text("Not playing")
|
Text("Not playing")
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
.onAppear {
|
|
||||||
#if !os(macOS)
|
|
||||||
currentPage = .queue
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
@ -3,15 +3,16 @@ import Siesta
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct PlaylistsView: View {
|
struct PlaylistsView: View {
|
||||||
@EnvironmentObject<PlayerModel> private var player
|
|
||||||
@EnvironmentObject<PlaylistsModel> private var model
|
|
||||||
|
|
||||||
@State private var showingNewPlaylist = false
|
@State private var showingNewPlaylist = false
|
||||||
@State private var createdPlaylist: Playlist?
|
@State private var createdPlaylist: Playlist?
|
||||||
|
|
||||||
@State private var showingEditPlaylist = false
|
@State private var showingEditPlaylist = false
|
||||||
@State private var editedPlaylist: Playlist?
|
@State private var editedPlaylist: Playlist?
|
||||||
|
|
||||||
|
@EnvironmentObject<AccountsModel> private var accounts
|
||||||
|
@EnvironmentObject<PlayerModel> private var player
|
||||||
|
@EnvironmentObject<PlaylistsModel> private var model
|
||||||
|
|
||||||
@Namespace private var focusNamespace
|
@Namespace private var focusNamespace
|
||||||
|
|
||||||
var items: [ContentItem] {
|
var items: [ContentItem] {
|
||||||
@ -101,6 +102,9 @@ struct PlaylistsView: View {
|
|||||||
.onAppear {
|
.onAppear {
|
||||||
model.load()
|
model.load()
|
||||||
}
|
}
|
||||||
|
.onChange(of: accounts.current) { _ in
|
||||||
|
model.load(force: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
|
@ -15,15 +15,13 @@ struct VideoBanner: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(alignment: .top, spacing: 12) {
|
HStack(alignment: stackAlignment, spacing: 12) {
|
||||||
VStack(spacing: thumbnailStackSpacing) {
|
VStack(spacing: thumbnailStackSpacing) {
|
||||||
smallThumbnail
|
smallThumbnail
|
||||||
|
|
||||||
if !playbackTime.isNil {
|
#if !os(tvOS)
|
||||||
ProgressView(value: progressViewValue, total: progressViewTotal)
|
progressView
|
||||||
.progressViewStyle(.linear)
|
#endif
|
||||||
.frame(maxWidth: thumbnailWidth)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
Text(video.title)
|
Text(video.title)
|
||||||
@ -38,6 +36,10 @@ struct VideoBanner: View {
|
|||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
|
#if os(tvOS)
|
||||||
|
progressView
|
||||||
|
#endif
|
||||||
|
|
||||||
if let time = (videoDuration ?? video.length).formattedAsPlaybackTime() {
|
if let time = (videoDuration ?? video.length).formattedAsPlaybackTime() {
|
||||||
Text(time)
|
Text(time)
|
||||||
.fontWeight(.light)
|
.fontWeight(.light)
|
||||||
@ -52,11 +54,19 @@ struct VideoBanner: View {
|
|||||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 100, alignment: .center)
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 100, alignment: .center)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var stackAlignment: VerticalAlignment {
|
||||||
|
#if os(macOS)
|
||||||
|
playbackTime.isNil ? .center : .top
|
||||||
|
#else
|
||||||
|
.center
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private var thumbnailStackSpacing: Double {
|
private var thumbnailStackSpacing: Double {
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
8
|
8
|
||||||
#else
|
#else
|
||||||
3
|
2
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,22 +78,32 @@ struct VideoBanner: View {
|
|||||||
}
|
}
|
||||||
.indicator(.activity)
|
.indicator(.activity)
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
.frame(width: thumbnailWidth, height: 100)
|
.frame(width: thumbnailWidth, height: 140)
|
||||||
.mask(RoundedRectangle(cornerRadius: 12))
|
.mask(RoundedRectangle(cornerRadius: 12))
|
||||||
#else
|
#else
|
||||||
.frame(width: thumbnailWidth, height: 50)
|
.frame(width: thumbnailWidth, height: 60)
|
||||||
.mask(RoundedRectangle(cornerRadius: 6))
|
.mask(RoundedRectangle(cornerRadius: 6))
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private var thumbnailWidth: Double {
|
private var thumbnailWidth: Double {
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
177
|
230
|
||||||
#else
|
#else
|
||||||
88
|
100
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var progressView: some View {
|
||||||
|
Group {
|
||||||
|
if !playbackTime.isNil {
|
||||||
|
ProgressView(value: progressViewValue, total: progressViewTotal)
|
||||||
|
.progressViewStyle(.linear)
|
||||||
|
.frame(maxWidth: thumbnailWidth)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var progressViewValue: Double {
|
private var progressViewValue: Double {
|
||||||
[playbackTime?.seconds, videoDuration].compactMap { $0 }.min() ?? 0
|
[playbackTime?.seconds, videoDuration].compactMap { $0 }.min() ?? 0
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,10 @@ struct NowPlayingView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var content: some View {
|
var content: some View {
|
||||||
ScrollView(.vertical) {
|
List {
|
||||||
VStack(alignment: .leading) {
|
|
||||||
if !inInfoViewController, let item = player.currentItem {
|
|
||||||
Group {
|
Group {
|
||||||
header("Now Playing")
|
if !inInfoViewController, let item = player.currentItem {
|
||||||
|
Section(header: Text("Now Playing")) {
|
||||||
Button {
|
Button {
|
||||||
player.presentPlayer()
|
player.presentPlayer()
|
||||||
} label: {
|
} label: {
|
||||||
@ -29,14 +27,10 @@ struct NowPlayingView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onPlayPauseCommand(perform: player.togglePlay)
|
.onPlayPauseCommand(perform: player.togglePlay)
|
||||||
.padding(.bottom, 20)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
header("Playing Next")
|
Section(header: Text("Playing Next")) {
|
||||||
|
|
||||||
if player.queue.isEmpty {
|
if player.queue.isEmpty {
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Text("Playback queue is empty")
|
Text("Playback queue is empty")
|
||||||
.padding([.vertical, .leading], 40)
|
.padding([.vertical, .leading], 40)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
@ -55,17 +49,10 @@ struct NowPlayingView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
header("Played Previously")
|
|
||||||
|
|
||||||
if player.history.isEmpty {
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Text("History is empty")
|
|
||||||
.padding([.vertical, .leading], 40)
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !player.history.isEmpty {
|
||||||
|
Section(header: Text("Played Previously")) {
|
||||||
ForEach(player.history) { item in
|
ForEach(player.history) { item in
|
||||||
Button {
|
Button {
|
||||||
player.playHistory(item)
|
player.playHistory(item)
|
||||||
@ -84,17 +71,22 @@ struct NowPlayingView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.vertical)
|
|
||||||
.padding(.horizontal, 40)
|
|
||||||
}
|
}
|
||||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 260, maxHeight: .infinity, alignment: .leading)
|
}
|
||||||
|
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
|
||||||
|
.padding(.vertical, 20)
|
||||||
|
// .padding(.horizontal, 40)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, inInfoViewController ? 40 : 0)
|
||||||
|
.listStyle(.grouped)
|
||||||
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 560, maxHeight: .infinity, alignment: .leading)
|
||||||
}
|
}
|
||||||
|
|
||||||
func header(_ text: String) -> some View {
|
func header(_ text: String) -> some View {
|
||||||
Text(text)
|
Text(text)
|
||||||
.font((inInfoViewController ? Font.system(size: 40) : .title3).bold())
|
.font((inInfoViewController ? Font.system(size: 40) : .title3).bold())
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
.padding(.leading, 40)
|
// .padding(.leading, 40)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user