Improve video banner and playback queue view

This commit is contained in:
Arkadiusz Fal
2021-10-23 12:13:05 +02:00
parent 8a43ed9503
commit 28709a2c80
8 changed files with 124 additions and 103 deletions

View File

@@ -8,14 +8,21 @@ struct PlayerQueueView: View {
var body: some View {
List {
playingNext
playedPreviously
Group {
playingNext
playedPreviously
}
.padding(.vertical, 5)
.listRowInsets(EdgeInsets())
#if os(iOS)
.padding(.horizontal, 10)
#endif
}
#if os(macOS)
.listStyle(.inset)
#elseif os(iOS)
.listStyle(.insetGrouped)
.listStyle(.grouped)
#else
.listStyle(.plain)
#endif
@@ -44,23 +51,22 @@ struct PlayerQueueView: View {
}
var playedPreviously: some View {
Section(header: Text("Played Previously")) {
if player.history.isEmpty {
Text("History is empty")
.foregroundColor(.secondary)
}
ForEach(player.history) { item in
PlayerQueueRow(item: item, history: true, fullScreen: $fullScreen)
.contextMenu {
removeButton(item, history: true)
removeAllButton(history: true)
Group {
if !player.history.isEmpty {
Section(header: Text("Played Previously")) {
ForEach(player.history) { item in
PlayerQueueRow(item: item, history: true, fullScreen: $fullScreen)
.contextMenu {
removeButton(item, history: true)
removeAllButton(history: true)
}
#if os(iOS)
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
removeButton(item, history: true)
}
#endif
}
#if os(iOS)
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
removeButton(item, history: true)
}
#endif
}
}
}
}

View File

@@ -6,7 +6,6 @@ final class PlayerViewController: UIViewController {
var playerLoaded = false
var playerModel: PlayerModel!
var playerViewController = AVPlayerViewController()
var shouldResume = false
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
@@ -73,15 +72,9 @@ extension PlayerViewController: AVPlayerViewControllerDelegate {
false
}
func playerViewControllerWillBeginDismissalTransition(_: AVPlayerViewController) {
shouldResume = playerModel.isPlaying
}
func playerViewControllerWillBeginDismissalTransition(_: AVPlayerViewController) {}
func playerViewControllerDidEndDismissalTransition(_: AVPlayerViewController) {
if shouldResume {
playerModel.play()
}
dismiss(animated: false)
}

View File

@@ -87,6 +87,10 @@ struct VideoDetails: View {
}
}
.onAppear {
if video.isNil {
currentPage = .queue
}
guard video != nil, accounts.app.supportsSubscriptions else {
subscribed = false
return
@@ -94,6 +98,15 @@ struct VideoDetails: View {
subscribed = subscriptions.isSubscribing(video!.channel.id)
}
.onChange(of: sidebarQueue) { queue in
#if !os(macOS)
if queue {
currentPage = .details
} else {
currentPage = .queue
}
#endif
}
.edgesIgnoringSafeArea(.horizontal)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
}
@@ -112,11 +125,6 @@ struct VideoDetails: View {
} else {
Text("Not playing")
.foregroundColor(.secondary)
.onAppear {
#if !os(macOS)
currentPage = .queue
#endif
}
}
Spacer()

View File

@@ -3,15 +3,16 @@ import Siesta
import SwiftUI
struct PlaylistsView: View {
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<PlaylistsModel> private var model
@State private var showingNewPlaylist = false
@State private var createdPlaylist: Playlist?
@State private var showingEditPlaylist = false
@State private var editedPlaylist: Playlist?
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<PlaylistsModel> private var model
@Namespace private var focusNamespace
var items: [ContentItem] {
@@ -101,6 +102,9 @@ struct PlaylistsView: View {
.onAppear {
model.load()
}
.onChange(of: accounts.current) { _ in
model.load(force: true)
}
}
#if os(tvOS)

View File

@@ -15,15 +15,13 @@ struct VideoBanner: View {
}
var body: some View {
HStack(alignment: .top, spacing: 12) {
HStack(alignment: stackAlignment, spacing: 12) {
VStack(spacing: thumbnailStackSpacing) {
smallThumbnail
if !playbackTime.isNil {
ProgressView(value: progressViewValue, total: progressViewTotal)
.progressViewStyle(.linear)
.frame(maxWidth: thumbnailWidth)
}
#if !os(tvOS)
progressView
#endif
}
VStack(alignment: .leading, spacing: 4) {
Text(video.title)
@@ -38,6 +36,10 @@ struct VideoBanner: View {
Spacer()
#if os(tvOS)
progressView
#endif
if let time = (videoDuration ?? video.length).formattedAsPlaybackTime() {
Text(time)
.fontWeight(.light)
@@ -52,11 +54,19 @@ struct VideoBanner: View {
.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 {
#if os(tvOS)
8
#else
3
2
#endif
}
@@ -68,22 +78,32 @@ struct VideoBanner: View {
}
.indicator(.activity)
#if os(tvOS)
.frame(width: thumbnailWidth, height: 100)
.frame(width: thumbnailWidth, height: 140)
.mask(RoundedRectangle(cornerRadius: 12))
#else
.frame(width: thumbnailWidth, height: 50)
.frame(width: thumbnailWidth, height: 60)
.mask(RoundedRectangle(cornerRadius: 6))
#endif
}
private var thumbnailWidth: Double {
#if os(tvOS)
177
230
#else
88
100
#endif
}
private var progressView: some View {
Group {
if !playbackTime.isNil {
ProgressView(value: progressViewValue, total: progressViewTotal)
.progressViewStyle(.linear)
.frame(maxWidth: thumbnailWidth)
}
}
}
private var progressViewValue: Double {
[playbackTime?.seconds, videoDuration].compactMap { $0 }.min() ?? 0
}