mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Home queue
This commit is contained in:
@@ -34,6 +34,10 @@ private struct InQueueListingKey: EnvironmentKey {
|
||||
static let defaultValue = false
|
||||
}
|
||||
|
||||
private struct NoListingDividersKey: EnvironmentKey {
|
||||
static let defaultValue = false
|
||||
}
|
||||
|
||||
enum ListingStyle: String, CaseIterable, Defaults.Serializable {
|
||||
case cells
|
||||
case list
|
||||
@@ -113,4 +117,8 @@ extension EnvironmentValues {
|
||||
set { self[InQueueListingKey.self] = newValue }
|
||||
}
|
||||
|
||||
var noListingDividers: Bool {
|
||||
get { self[NoListingDividersKey.self] }
|
||||
set { self[NoListingDividersKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
@@ -62,15 +62,19 @@ struct HomeView: View {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if os(iOS)
|
||||
.padding(.top, RefreshControl.navigationBarTitleDisplayMode == .inline ? 15 : 0)
|
||||
#else
|
||||
.padding(.top, 15)
|
||||
#endif
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 40)
|
||||
.padding(.horizontal, 40)
|
||||
#else
|
||||
.padding(.horizontal, 15)
|
||||
.padding(.horizontal, 15)
|
||||
#endif
|
||||
|
||||
QueueView()
|
||||
.padding(.vertical, 15)
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 40)
|
||||
#else
|
||||
.padding(.horizontal, 15)
|
||||
#endif
|
||||
|
||||
if !accounts.current.isNil, showFavoritesInHome {
|
||||
|
69
Shared/Home/QueueView.swift
Normal file
69
Shared/Home/QueueView.swift
Normal file
@@ -0,0 +1,69 @@
|
||||
import SwiftUI
|
||||
|
||||
struct QueueView: View {
|
||||
@State private var expanded = false
|
||||
|
||||
@ObservedObject private var player = PlayerModel.shared
|
||||
|
||||
var body: some View {
|
||||
LazyVStack {
|
||||
if !items.isEmpty {
|
||||
HStack {
|
||||
sectionLabel("Next in queue")
|
||||
Button {
|
||||
withAnimation {
|
||||
expanded.toggle()
|
||||
}
|
||||
} label: {
|
||||
Label("Show more", systemImage: expanded ? "chevron.up" : "chevron.down")
|
||||
.animation(nil, value: expanded)
|
||||
.foregroundColor(.accentColor)
|
||||
.imageScale(.large)
|
||||
.labelStyle(.iconOnly)
|
||||
}
|
||||
.opacity(items.count > 1 ? 1 : 0)
|
||||
}
|
||||
ForEach(limitedItems) { item in
|
||||
ContentItemView(item: .init(video: item.video))
|
||||
.environment(\.listingStyle, .list)
|
||||
.environment(\.inQueueListing, true)
|
||||
.environment(\.noListingDividers, limit == 1)
|
||||
.transition(.opacity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var limitedItems: [PlayerQueueItem] {
|
||||
if let limit {
|
||||
return Array(items.prefix(limit))
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
var items: [PlayerQueueItem] {
|
||||
player.queue
|
||||
}
|
||||
|
||||
var limit: Int? {
|
||||
if !expanded {
|
||||
return 1
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func sectionLabel(_ label: String) -> some View {
|
||||
Text(label.localized())
|
||||
.font(.title3.bold())
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
struct QueueView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
QueueView()
|
||||
}
|
||||
}
|
@@ -254,7 +254,7 @@ struct VideoBanner: View {
|
||||
PlayingIndicatorView(video: video, height: 10)
|
||||
.frame(width: 12, alignment: .trailing)
|
||||
.padding(.trailing, 3)
|
||||
.padding(.bottom, timeLabel == nil ? 3 : 0)
|
||||
.padding(.bottom, timeLabel == nil ? 3 : -5)
|
||||
|
||||
if let timeLabel {
|
||||
Text(timeLabel)
|
||||
|
@@ -4,6 +4,7 @@ import SwiftUI
|
||||
struct ContentItemView: View {
|
||||
let item: ContentItem
|
||||
@Environment(\.listingStyle) private var listingStyle
|
||||
@Environment(\.noListingDividers) private var noListingDividers
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
@@ -25,16 +26,19 @@ struct ContentItemView: View {
|
||||
if listingStyle == .cells {
|
||||
VideoCell(video: video)
|
||||
} else {
|
||||
PlayerQueueRow(item: .init(video))
|
||||
let item = PlayerQueueItem(video)
|
||||
PlayerQueueRow(item: item)
|
||||
.contextMenu {
|
||||
VideoContextMenuView(video: video)
|
||||
}
|
||||
.id(item.id)
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 30)
|
||||
#endif
|
||||
|
||||
#if !os(tvOS)
|
||||
Divider()
|
||||
.opacity(noListingDividers ? 0 : 1)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user