mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 13:50:32 +05:30
Refactor context menu
This commit is contained in:
parent
441f3c9e80
commit
8ab42322fc
@ -30,6 +30,10 @@ private struct InNavigationViewKey: EnvironmentKey {
|
|||||||
static let defaultValue = true
|
static let defaultValue = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct InQueueListingKey: EnvironmentKey {
|
||||||
|
static let defaultValue = false
|
||||||
|
}
|
||||||
|
|
||||||
enum ListingStyle: String, CaseIterable, Defaults.Serializable {
|
enum ListingStyle: String, CaseIterable, Defaults.Serializable {
|
||||||
case cells
|
case cells
|
||||||
case list
|
case list
|
||||||
@ -103,4 +107,10 @@ extension EnvironmentValues {
|
|||||||
get { self[InNavigationViewKey.self] }
|
get { self[InNavigationViewKey.self] }
|
||||||
set { self[InNavigationViewKey.self] = newValue }
|
set { self[InNavigationViewKey.self] = newValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var inQueueListing: Bool {
|
||||||
|
get { self[InQueueListingKey.self] }
|
||||||
|
set { self[InQueueListingKey.self] = newValue }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import SwiftUI
|
|||||||
|
|
||||||
struct PlayerQueueView: View {
|
struct PlayerQueueView: View {
|
||||||
var sidebarQueue: Bool
|
var sidebarQueue: Bool
|
||||||
@Binding var fullScreen: Bool
|
|
||||||
|
|
||||||
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
||||||
var watches: FetchedResults<Watch>
|
var watches: FetchedResults<Watch>
|
||||||
@ -138,7 +137,7 @@ struct PlayerQueueView: View {
|
|||||||
struct PlayerQueueView_Previews: PreviewProvider {
|
struct PlayerQueueView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack {
|
VStack {
|
||||||
PlayerQueueView(sidebarQueue: true, fullScreen: .constant(true))
|
PlayerQueueView(sidebarQueue: true)
|
||||||
}
|
}
|
||||||
.injectFixtureEnvironmentObjects()
|
.injectFixtureEnvironmentObjects()
|
||||||
}
|
}
|
||||||
|
@ -394,14 +394,14 @@ struct VideoPlayerView: View {
|
|||||||
if !fullScreenPlayer {
|
if !fullScreenPlayer {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
if sidebarQueue {
|
if sidebarQueue {
|
||||||
PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails)
|
PlayerQueueView(sidebarQueue: true)
|
||||||
.frame(maxWidth: 350)
|
.frame(maxWidth: 350)
|
||||||
.background(colorScheme == .dark ? Color.black : Color.white)
|
.background(colorScheme == .dark ? Color.black : Color.white)
|
||||||
.transition(.move(edge: .bottom))
|
.transition(.move(edge: .bottom))
|
||||||
}
|
}
|
||||||
#elseif os(macOS)
|
#elseif os(macOS)
|
||||||
if Defaults[.playerSidebar] != .never {
|
if Defaults[.playerSidebar] != .never {
|
||||||
PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails)
|
PlayerQueueView(sidebarQueue: true)
|
||||||
.frame(width: 350)
|
.frame(width: 350)
|
||||||
.background(colorScheme == .dark ? Color.black : Color.white)
|
.background(colorScheme == .dark ? Color.black : Color.white)
|
||||||
}
|
}
|
||||||
|
@ -197,22 +197,9 @@ struct WatchNextView: View {
|
|||||||
let queueForMoreVideos = player.queue.isEmpty ? [] : player.queue.suffix(from: model.isAutoplaying ? 1 : 0)
|
let queueForMoreVideos = player.queue.isEmpty ? [] : player.queue.suffix(from: model.isAutoplaying ? 1 : 0)
|
||||||
if !queueForMoreVideos.isEmpty {
|
if !queueForMoreVideos.isEmpty {
|
||||||
ForEach(queueForMoreVideos) { item in
|
ForEach(queueForMoreVideos) { item in
|
||||||
PlayerQueueRow(item: item)
|
ContentItemView(item: .init(video: item.video))
|
||||||
.contextMenu {
|
.environment(\.inQueueListing, true)
|
||||||
removeButton(item)
|
.environment(\.listingStyle, .list)
|
||||||
removeAllButton()
|
|
||||||
|
|
||||||
if let video = item.video {
|
|
||||||
VideoContextMenuView(video: video)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if os(tvOS)
|
|
||||||
.padding(.horizontal, 30)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !os(tvOS)
|
|
||||||
Divider()
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
} else if player.playbackMode != .related && player.playbackMode != .loopOne {
|
} else if player.playbackMode != .related && player.playbackMode != .loopOne {
|
||||||
Label(
|
Label(
|
||||||
@ -239,22 +226,6 @@ struct WatchNextView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func removeButton(_ item: PlayerQueueItem) -> some View {
|
|
||||||
Button {
|
|
||||||
player.remove(item)
|
|
||||||
} label: {
|
|
||||||
Label("Remove from the queue", systemImage: "trash")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func removeAllButton() -> some View {
|
|
||||||
Button {
|
|
||||||
player.removeQueueItems()
|
|
||||||
} label: {
|
|
||||||
Label("Clear the queue", systemImage: "trash.fill")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WatchNextView_Previews: PreviewProvider {
|
struct WatchNextView_Previews: PreviewProvider {
|
||||||
|
@ -8,6 +8,7 @@ struct VideoContextMenuView: View {
|
|||||||
|
|
||||||
@Environment(\.inChannelView) private var inChannelView
|
@Environment(\.inChannelView) private var inChannelView
|
||||||
@Environment(\.inChannelPlaylistView) private var inChannelPlaylistView
|
@Environment(\.inChannelPlaylistView) private var inChannelPlaylistView
|
||||||
|
@Environment(\.inQueueListing) private var inQueueListing
|
||||||
@Environment(\.navigationStyle) private var navigationStyle
|
@Environment(\.navigationStyle) private var navigationStyle
|
||||||
@Environment(\.currentPlaylistID) private var playlistID
|
@Environment(\.currentPlaylistID) private var playlistID
|
||||||
|
|
||||||
@ -36,6 +37,12 @@ struct VideoContextMenuView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder var contextMenu: some View {
|
@ViewBuilder var contextMenu: some View {
|
||||||
|
if inQueueListing {
|
||||||
|
if let item = player.queue.first(where: { $0.videoID == video.videoID }) {
|
||||||
|
removeFromQueueButton(item)
|
||||||
|
}
|
||||||
|
removeAllFromQueueButton()
|
||||||
|
}
|
||||||
if !video.localStreamIsDirectory {
|
if !video.localStreamIsDirectory {
|
||||||
if saveHistory {
|
if saveHistory {
|
||||||
Section {
|
Section {
|
||||||
@ -340,4 +347,20 @@ struct VideoContextMenuView: View {
|
|||||||
Label("Remove from Playlist", systemImage: "text.badge.minus")
|
Label("Remove from Playlist", systemImage: "text.badge.minus")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func removeFromQueueButton(_ item: PlayerQueueItem) -> some View {
|
||||||
|
Button {
|
||||||
|
player.remove(item)
|
||||||
|
} label: {
|
||||||
|
Label("Remove from the queue", systemImage: "trash")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func removeAllFromQueueButton() -> some View {
|
||||||
|
Button {
|
||||||
|
player.removeQueueItems()
|
||||||
|
} label: {
|
||||||
|
Label("Clear the queue", systemImage: "trash.fill")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user