mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Channel playlists support
This commit is contained in:
@@ -14,7 +14,7 @@ struct ChannelCell: View {
|
||||
Button {
|
||||
let recent = RecentItem(from: channel)
|
||||
recents.add(recent)
|
||||
navigation.isChannelOpen = true
|
||||
navigation.presentingChannel = true
|
||||
|
||||
if navigationStyle == .sidebar {
|
||||
navigation.sidebarSectionChanged.toggle()
|
||||
@@ -30,10 +30,13 @@ struct ChannelCell: View {
|
||||
|
||||
var content: some View {
|
||||
VStack {
|
||||
Text("Channel".uppercased())
|
||||
.foregroundColor(.secondary)
|
||||
.fontWeight(.light)
|
||||
.opacity(0.6)
|
||||
HStack(alignment: .top, spacing: 3) {
|
||||
Image(systemName: "person.crop.rectangle")
|
||||
Text("Channel".uppercased())
|
||||
.fontWeight(.light)
|
||||
.opacity(0.6)
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
WebImage(url: channel.thumbnailURL)
|
||||
.resizable()
|
||||
@@ -44,20 +47,17 @@ struct ChannelCell: View {
|
||||
.frame(width: 88, height: 88)
|
||||
.clipShape(Circle())
|
||||
|
||||
Group {
|
||||
DetailBadge(text: channel.name, style: .prominent)
|
||||
DetailBadge(text: channel.name, style: .prominent)
|
||||
|
||||
Group {
|
||||
if let subscriptions = channel.subscriptionsString {
|
||||
Text("\(subscriptions) subscribers")
|
||||
.foregroundColor(.secondary)
|
||||
} else {
|
||||
Text("")
|
||||
}
|
||||
Group {
|
||||
if let subscriptions = channel.subscriptionsString {
|
||||
Text("\(subscriptions) subscribers")
|
||||
.foregroundColor(.secondary)
|
||||
} else {
|
||||
Text("")
|
||||
}
|
||||
.frame(height: 20)
|
||||
}
|
||||
.offset(x: 0, y: -15)
|
||||
.frame(height: 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
68
Shared/Views/ChannelPlaylistCell.swift
Normal file
68
Shared/Views/ChannelPlaylistCell.swift
Normal file
@@ -0,0 +1,68 @@
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct ChannelPlaylistCell: View {
|
||||
let playlist: ChannelPlaylist
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
let recent = RecentItem(from: playlist)
|
||||
recents.add(recent)
|
||||
navigation.presentingPlaylist = true
|
||||
|
||||
if navigationStyle == .sidebar {
|
||||
navigation.sidebarSectionChanged.toggle()
|
||||
navigation.tabSelection = .recentlyOpened(recent.tag)
|
||||
}
|
||||
} label: {
|
||||
content
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||
.contentShape(RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
var content: some View {
|
||||
VStack {
|
||||
HStack(alignment: .top, spacing: 3) {
|
||||
Image(systemName: "list.and.film")
|
||||
Text("Playlist".uppercased())
|
||||
.fontWeight(.light)
|
||||
.opacity(0.6)
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
WebImage(url: playlist.thumbnailURL)
|
||||
.resizable()
|
||||
.placeholder {
|
||||
Rectangle().fill(Color("PlaceholderColor"))
|
||||
}
|
||||
.indicator(.progress)
|
||||
.frame(width: 165, height: 88)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||
|
||||
Group {
|
||||
DetailBadge(text: playlist.title, style: .prominent)
|
||||
.lineLimit(2)
|
||||
|
||||
Text("\(playlist.videosCount ?? playlist.videos.count) videos")
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
.frame(height: 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ChannelPlaylistCell_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ChannelPlaylistCell(playlist: ChannelPlaylist.fixture)
|
||||
.frame(maxWidth: 320)
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
74
Shared/Views/ChannelPlaylistView.swift
Normal file
74
Shared/Views/ChannelPlaylistView.swift
Normal file
@@ -0,0 +1,74 @@
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct ChannelPlaylistView: View {
|
||||
var playlist: ChannelPlaylist
|
||||
|
||||
@StateObject private var store = Store<ChannelPlaylist>()
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.inNavigationView) private var inNavigationView
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
|
||||
var items: [ContentItem] {
|
||||
ContentItem.array(of: store.item?.videos ?? [])
|
||||
}
|
||||
|
||||
var resource: Resource? {
|
||||
accounts.api.channelPlaylist(playlist.id)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
#if os(iOS)
|
||||
if inNavigationView {
|
||||
content
|
||||
} else {
|
||||
PlayerControlsView {
|
||||
content
|
||||
}
|
||||
}
|
||||
#else
|
||||
PlayerControlsView {
|
||||
content
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
var content: some View {
|
||||
VStack(alignment: .leading) {
|
||||
#if os(tvOS)
|
||||
Text(playlist.title)
|
||||
.font(.title2)
|
||||
.frame(alignment: .leading)
|
||||
#endif
|
||||
VerticalCells(items: items)
|
||||
}
|
||||
.onAppear {
|
||||
resource?.addObserver(store)
|
||||
resource?.loadIfNeeded()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
if inNavigationView {
|
||||
Button("Done") {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle(playlist.title)
|
||||
|
||||
#else
|
||||
.background(.thickMaterial)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
struct ChannelPlaylistView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ChannelPlaylistView(playlist: ChannelPlaylist.fixture)
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
@@ -6,17 +6,17 @@ struct ChannelVideosView: View {
|
||||
|
||||
@StateObject private var store = Store<Channel>()
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.inNavigationView) private var inNavigationView
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
#if os(iOS)
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
#endif
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
|
||||
@Namespace private var focusNamespace
|
||||
|
||||
var videos: [ContentItem] {
|
||||
@@ -88,8 +88,7 @@ struct ChannelVideosView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if os(tvOS)
|
||||
#else
|
||||
.background(.thickMaterial)
|
||||
#endif
|
||||
.modifier(UnsubscribeAlertModifier())
|
||||
|
@@ -8,7 +8,7 @@ struct ContentItemView: View {
|
||||
Group {
|
||||
switch item.contentType {
|
||||
case .playlist:
|
||||
VideoCell(video: item.video)
|
||||
ChannelPlaylistCell(playlist: item.playlist)
|
||||
case .channel:
|
||||
ChannelCell(channel: item.channel)
|
||||
default:
|
||||
|
@@ -73,7 +73,6 @@ struct DetailBadge: View {
|
||||
|
||||
var body: some View {
|
||||
Text(text)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
.padding(10)
|
||||
.modifier(StyleModifier(style: style))
|
||||
|
@@ -25,6 +25,10 @@ struct SearchView: View {
|
||||
|
||||
private var videos = [Video]()
|
||||
|
||||
var items: [ContentItem] {
|
||||
state.store.collection.sorted { $0 < $1 }
|
||||
}
|
||||
|
||||
init(_ query: SearchQuery? = nil, videos: [Video] = [Video]()) {
|
||||
self.query = query
|
||||
self.videos = videos
|
||||
@@ -42,11 +46,11 @@ struct SearchView: View {
|
||||
filtersHorizontalStack
|
||||
}
|
||||
|
||||
HorizontalCells(items: state.store.collection)
|
||||
HorizontalCells(items: items)
|
||||
}
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
#else
|
||||
VerticalCells(items: state.store.collection)
|
||||
VerticalCells(items: items)
|
||||
#endif
|
||||
|
||||
if noResults {
|
||||
@@ -173,7 +177,7 @@ struct SearchView: View {
|
||||
}
|
||||
|
||||
fileprivate var noResults: Bool {
|
||||
state.store.collection.isEmpty && !state.isLoading && !state.query.isEmpty
|
||||
items.isEmpty && !state.isLoading && !state.query.isEmpty
|
||||
}
|
||||
|
||||
var recentQueries: some View {
|
||||
|
@@ -85,7 +85,7 @@ struct VideoContextMenuView: View {
|
||||
Button {
|
||||
let recent = RecentItem(from: video.channel)
|
||||
recents.add(recent)
|
||||
navigation.isChannelOpen = true
|
||||
navigation.presentingChannel = true
|
||||
|
||||
if navigationStyle == .sidebar {
|
||||
navigation.sidebarSectionChanged.toggle()
|
||||
|
Reference in New Issue
Block a user