mirror of
https://github.com/yattee/yattee.git
synced 2025-12-30 08:22:31 +00:00
Simplify video views
This commit is contained in:
@@ -1,157 +0,0 @@
|
||||
import Defaults
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct PlaylistsView: View {
|
||||
@ObservedObject private var store = Store<[Playlist]>()
|
||||
|
||||
@Default(.selectedPlaylistID) private var selectedPlaylistID
|
||||
|
||||
@State private var showingNewPlaylist = false
|
||||
@State private var createdPlaylist: Playlist?
|
||||
|
||||
@State private var showingEditPlaylist = false
|
||||
@State private var editedPlaylist: Playlist?
|
||||
|
||||
var resource: Resource {
|
||||
InvidiousAPI.shared.playlists
|
||||
}
|
||||
|
||||
init() {
|
||||
resource.addObserver(store)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
VStack(alignment: .center, spacing: 2) {
|
||||
#if os(tvOS)
|
||||
HStack {
|
||||
if store.collection.isEmpty {
|
||||
Text("No Playlists")
|
||||
.foregroundColor(.secondary)
|
||||
} else {
|
||||
Text("Current Playlist")
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
selectPlaylistButton
|
||||
}
|
||||
|
||||
if currentPlaylist != nil {
|
||||
editPlaylistButton
|
||||
}
|
||||
|
||||
newPlaylistButton
|
||||
.padding(.leading, 40)
|
||||
}
|
||||
.scaleEffect(0.85)
|
||||
#endif
|
||||
|
||||
if currentPlaylist != nil {
|
||||
if currentPlaylist!.videos.isEmpty {
|
||||
Spacer()
|
||||
|
||||
Text("Playlist is empty\n\nTap and hold on a video and then tap \"Add to Playlist\"")
|
||||
.foregroundColor(.secondary)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
Spacer()
|
||||
} else {
|
||||
VideosView(videos: currentPlaylist!.videos)
|
||||
}
|
||||
} else {
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
#if !os(macOS)
|
||||
.fullScreenCover(isPresented: $showingNewPlaylist, onDismiss: selectCreatedPlaylist) {
|
||||
PlaylistFormView(playlist: $createdPlaylist)
|
||||
}
|
||||
.fullScreenCover(isPresented: $showingEditPlaylist, onDismiss: selectEditedPlaylist) {
|
||||
PlaylistFormView(playlist: $editedPlaylist)
|
||||
}
|
||||
#endif
|
||||
.onAppear {
|
||||
resource.loadIfNeeded()?.onSuccess { _ in
|
||||
selectPlaylist(selectedPlaylistID)
|
||||
}
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Playlists")
|
||||
#elseif os(iOS)
|
||||
.navigationBarItems(trailing: newPlaylistButton)
|
||||
#endif
|
||||
}
|
||||
|
||||
func selectPlaylist(_ id: String?) {
|
||||
selectedPlaylistID = id
|
||||
}
|
||||
|
||||
func selectCreatedPlaylist() {
|
||||
guard createdPlaylist != nil else {
|
||||
return
|
||||
}
|
||||
|
||||
resource.load().onSuccess { _ in
|
||||
self.selectPlaylist(createdPlaylist?.id)
|
||||
|
||||
self.createdPlaylist = nil
|
||||
}
|
||||
}
|
||||
|
||||
func selectEditedPlaylist() {
|
||||
if editedPlaylist == nil {
|
||||
selectPlaylist(nil)
|
||||
}
|
||||
|
||||
resource.load().onSuccess { _ in
|
||||
selectPlaylist(editedPlaylist?.id)
|
||||
|
||||
self.editedPlaylist = nil
|
||||
}
|
||||
}
|
||||
|
||||
var currentPlaylist: Playlist? {
|
||||
store.collection.first { $0.id == selectedPlaylistID } ?? store.collection.first
|
||||
}
|
||||
|
||||
var selectPlaylistButton: some View {
|
||||
Button(currentPlaylist?.title ?? "Select playlist") {
|
||||
guard currentPlaylist != nil else {
|
||||
return
|
||||
}
|
||||
|
||||
selectPlaylist(store.collection.next(after: currentPlaylist!)?.id)
|
||||
}
|
||||
.contextMenu {
|
||||
ForEach(store.collection) { playlist in
|
||||
Button(playlist.title) {
|
||||
selectPlaylist(playlist.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var editPlaylistButton: some View {
|
||||
Button(action: {
|
||||
self.editedPlaylist = self.currentPlaylist
|
||||
self.showingEditPlaylist = true
|
||||
}) {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "pencil")
|
||||
Text("Edit")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var newPlaylistButton: some View {
|
||||
Button(action: { self.showingNewPlaylist = true }) {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "plus")
|
||||
#if os(tvOS)
|
||||
Text("New Playlist")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct PopularVideosView: View {
|
||||
@ObservedObject private var store = Store<[Video]>()
|
||||
|
||||
var resource = InvidiousAPI.shared.popular
|
||||
|
||||
init() {
|
||||
resource.addObserver(store)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VideosView(videos: store.collection)
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Popular")
|
||||
#endif
|
||||
.onAppear {
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
import Defaults
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct SearchView: View {
|
||||
@Default(.searchQuery) private var queryText
|
||||
@Default(.searchSortOrder) private var searchSortOrder
|
||||
@Default(.searchDate) private var searchDate
|
||||
@Default(.searchDuration) private var searchDuration
|
||||
|
||||
@ObservedObject private var store = Store<[Video]>()
|
||||
@ObservedObject private var query = SearchQuery()
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if !store.collection.isEmpty {
|
||||
VideosView(videos: store.collection)
|
||||
}
|
||||
|
||||
if store.collection.isEmpty && !resource.isLoading && !query.isEmpty {
|
||||
Text("No results")
|
||||
|
||||
if searchFiltersActive {
|
||||
Button("Reset search filters") {
|
||||
Defaults.reset(.searchDate, .searchDuration)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.searchable(text: $queryText)
|
||||
.onAppear {
|
||||
changeQuery {
|
||||
query.query = queryText
|
||||
query.sortBy = searchSortOrder
|
||||
query.date = searchDate
|
||||
query.duration = searchDuration
|
||||
}
|
||||
}
|
||||
.onChange(of: queryText) { queryText in
|
||||
changeQuery { query.query = queryText }
|
||||
}
|
||||
.onChange(of: searchSortOrder) { order in
|
||||
changeQuery { query.sortBy = order }
|
||||
}
|
||||
.onChange(of: searchDate) { date in
|
||||
changeQuery { query.date = date }
|
||||
}
|
||||
.onChange(of: searchDuration) { duration in
|
||||
changeQuery { query.duration = duration }
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Search")
|
||||
#endif
|
||||
}
|
||||
|
||||
func changeQuery(_ change: @escaping () -> Void = {}) {
|
||||
resource.removeObservers(ownedBy: store)
|
||||
change()
|
||||
|
||||
resource.addObserver(store)
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
|
||||
var resource: Resource {
|
||||
InvidiousAPI.shared.search(query)
|
||||
}
|
||||
|
||||
var searchFiltersActive: Bool {
|
||||
searchDate != nil || searchDuration != nil
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SubscriptionsView: View {
|
||||
@ObservedObject private var store = Store<[Video]>()
|
||||
|
||||
var resource = InvidiousAPI.shared.subscriptions
|
||||
|
||||
init() {
|
||||
resource.addObserver(store)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VideosView(videos: store.collection)
|
||||
.onAppear {
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
.refreshable {
|
||||
resource.load()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Subscriptions")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ struct TVNavigationView: View {
|
||||
.tabItem { Text("Subscriptions") }
|
||||
.tag(TabSelection.subscriptions)
|
||||
|
||||
PopularVideosView()
|
||||
PopularView()
|
||||
.tabItem { Text("Popular") }
|
||||
.tag(TabSelection.popular)
|
||||
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct TrendingView: View {
|
||||
@State private var category: TrendingCategory = .default
|
||||
@State private var country: Country = .pl
|
||||
@State private var selectingCountry = false
|
||||
|
||||
@ObservedObject private var store = Store<[Video]>()
|
||||
|
||||
var resource: Resource {
|
||||
InvidiousAPI.shared.trending(category: category, country: country)
|
||||
}
|
||||
|
||||
init() {
|
||||
resource.addObserver(store)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
VStack(alignment: .center, spacing: 2) {
|
||||
#if os(tvOS)
|
||||
HStack {
|
||||
Text("Category")
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
categoryButton
|
||||
|
||||
Text("Country")
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
countryFlag
|
||||
countryButton
|
||||
}
|
||||
.scaleEffect(0.85)
|
||||
#endif
|
||||
|
||||
VideosView(videos: store.collection)
|
||||
}
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Trending")
|
||||
#endif
|
||||
.onAppear {
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
var categoryButton: some View {
|
||||
Button(category.name) {
|
||||
setCategory(category.next())
|
||||
}
|
||||
.contextMenu {
|
||||
ForEach(TrendingCategory.allCases) { category in
|
||||
Button(category.name) { setCategory(category) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var countryFlag: some View {
|
||||
Text(country.flag)
|
||||
.font(.system(size: 60))
|
||||
}
|
||||
|
||||
var countryButton: some View {
|
||||
Button(country.rawValue) {
|
||||
selectingCountry.toggle()
|
||||
resource.removeObservers(ownedBy: store)
|
||||
}
|
||||
#if os(tvOS)
|
||||
.fullScreenCover(isPresented: $selectingCountry, onDismiss: { setCountry(country) }) {
|
||||
TrendingCountrySelectionView(selectedCountry: $country)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
fileprivate func setCategory(_ category: TrendingCategory) {
|
||||
resource.removeObservers(ownedBy: store)
|
||||
self.category = category
|
||||
resource.addObserver(store)
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
|
||||
fileprivate func setCountry(_ country: Country) {
|
||||
self.country = country
|
||||
resource.addObserver(store)
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct VideoCellView: View {
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
|
||||
var video: Video
|
||||
|
||||
var body: some View {
|
||||
Button(action: { navigationState.playVideo(video) }) {
|
||||
VStack(alignment: .leading) {
|
||||
ZStack {
|
||||
if let url = video.thumbnailURL(quality: .high) {
|
||||
AsyncImage(url: url) { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: 550, height: 310)
|
||||
} placeholder: {
|
||||
ProgressView()
|
||||
}
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
} else {
|
||||
Image(systemName: "exclamationmark.square")
|
||||
.frame(width: 550, height: 310)
|
||||
}
|
||||
|
||||
VStack {
|
||||
HStack(alignment: .top) {
|
||||
if video.live {
|
||||
DetailBadge(text: "Live", style: .outstanding)
|
||||
} else if video.upcoming {
|
||||
DetailBadge(text: "Upcoming", style: .informational)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
DetailBadge(text: video.author, style: .prominent)
|
||||
}
|
||||
.padding(10)
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack(alignment: .top) {
|
||||
Spacer()
|
||||
|
||||
if let time = video.playTime {
|
||||
DetailBadge(text: time, style: .prominent)
|
||||
}
|
||||
}
|
||||
.padding(10)
|
||||
}
|
||||
}
|
||||
.frame(width: 550, height: 310)
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
Text(video.title)
|
||||
.bold()
|
||||
.lineLimit(2)
|
||||
.multilineTextAlignment(.leading)
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom, 2)
|
||||
.frame(minHeight: 80, alignment: .top)
|
||||
.truncationMode(.middle)
|
||||
|
||||
HStack(spacing: 8) {
|
||||
if video.publishedDate != nil || video.views != 0 {
|
||||
if let date = video.publishedDate {
|
||||
Image(systemName: "calendar")
|
||||
Text(date)
|
||||
}
|
||||
|
||||
if video.views != 0 {
|
||||
Image(systemName: "eye")
|
||||
Text(video.viewsCount)
|
||||
}
|
||||
} else {
|
||||
Section {
|
||||
if video.live {
|
||||
Image(systemName: "camera.fill")
|
||||
Text("Premiering now")
|
||||
} else {
|
||||
Image(systemName: "questionmark.app.fill")
|
||||
Text("date and views unavailable")
|
||||
}
|
||||
}
|
||||
.opacity(0.6)
|
||||
}
|
||||
}
|
||||
.padding([.horizontal, .bottom])
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
.frame(width: 550, alignment: .leading)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.padding(.vertical)
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoCellView_Preview: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HStack {
|
||||
VideoCellView(video: Video.fixture)
|
||||
VideoCellView(video: Video.fixtureUpcomingWithoutPublishedOrViews)
|
||||
VideoCellView(video: Video.fixtureLiveWithoutPublishedOrViews)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,215 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct VideoListRowView: View {
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
|
||||
@Environment(\.isFocused) private var focused: Bool
|
||||
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
#endif
|
||||
|
||||
var video: Video
|
||||
|
||||
var body: some View {
|
||||
#if os(tvOS)
|
||||
Button(action: { navigationState.playVideo(video) }) {
|
||||
horizontalRow(detailsOnThumbnail: false)
|
||||
}
|
||||
#elseif os(macOS)
|
||||
NavigationLink(destination: VideoPlayerView(video)) {
|
||||
verticalRow
|
||||
}
|
||||
#else
|
||||
ZStack {
|
||||
#if os(macOS)
|
||||
verticalRow
|
||||
#else
|
||||
if verticalSizeClass == .compact {
|
||||
horizontalRow(padding: 4)
|
||||
} else {
|
||||
verticalRow
|
||||
}
|
||||
#endif
|
||||
|
||||
NavigationLink(destination: VideoPlayerView(video)) {
|
||||
EmptyView()
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
.opacity(0)
|
||||
.frame(height: 0)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func horizontalRow(detailsOnThumbnail: Bool = true, padding: Double = 0) -> some View {
|
||||
HStack(alignment: .top, spacing: 2) {
|
||||
if detailsOnThumbnail {
|
||||
thumbnailWithDetails()
|
||||
.padding(padding)
|
||||
} else {
|
||||
thumbnail(.medium, maxWidth: 320, maxHeight: 180)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
videoDetail(video.title, bold: true)
|
||||
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
if !detailsOnThumbnail {
|
||||
videoDetail(video.author, color: .secondary, bold: true)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
additionalDetails
|
||||
}
|
||||
.padding()
|
||||
.frame(minHeight: 180)
|
||||
|
||||
if !detailsOnThumbnail, let time = video.playTime {
|
||||
Spacer()
|
||||
|
||||
VStack(alignment: .center) {
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "clock")
|
||||
Text(time)
|
||||
.fontWeight(.bold)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var verticalRow: some View {
|
||||
VStack(alignment: .leading) {
|
||||
thumbnailWithDetails(minWidth: 250, maxWidth: 600, minHeight: 180)
|
||||
.frame(idealWidth: 320)
|
||||
.padding([.leading, .top, .trailing], 4)
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
videoDetail(video.title, bold: true)
|
||||
.padding(.bottom)
|
||||
|
||||
additionalDetails
|
||||
.padding(.bottom, 10)
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.horizontal, 8)
|
||||
}
|
||||
}
|
||||
|
||||
var additionalDetails: some View {
|
||||
VStack {
|
||||
if !video.published.isEmpty || video.views != 0 {
|
||||
HStack(spacing: 8) {
|
||||
if !video.published.isEmpty {
|
||||
Image(systemName: "calendar")
|
||||
Text(video.published)
|
||||
}
|
||||
|
||||
if video.views != 0 {
|
||||
Image(systemName: "eye")
|
||||
Text(video.viewsCount)
|
||||
}
|
||||
}
|
||||
#if os(tvOS)
|
||||
.foregroundColor(.secondary)
|
||||
#else
|
||||
.foregroundColor(focused ? .white : .secondary)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func thumbnailWithDetails(
|
||||
minWidth: Double = 250,
|
||||
maxWidth: Double = .infinity,
|
||||
minHeight: Double = 140,
|
||||
maxHeight: Double = .infinity
|
||||
) -> some View {
|
||||
ZStack(alignment: .trailing) {
|
||||
thumbnail(.maxres, minWidth: minWidth, maxWidth: maxWidth, minHeight: minHeight, maxHeight: maxHeight)
|
||||
|
||||
VStack(alignment: .trailing) {
|
||||
detailOnThinMaterial(video.author)
|
||||
.offset(x: -5, y: 5)
|
||||
|
||||
Spacer()
|
||||
|
||||
if let time = video.playTime {
|
||||
detailOnThinMaterial(time, bold: true)
|
||||
.offset(x: -5, y: -5)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func detailOnThinMaterial(_ text: String, bold: Bool = false) -> some View {
|
||||
Text(text)
|
||||
.fontWeight(bold ? .semibold : .regular)
|
||||
.padding(8)
|
||||
.background(.thinMaterial)
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
|
||||
func thumbnail(
|
||||
_ quality: Thumbnail.Quality,
|
||||
minWidth: Double = 320,
|
||||
maxWidth: Double = .infinity,
|
||||
minHeight: Double = 180,
|
||||
maxHeight: Double = .infinity
|
||||
) -> some View {
|
||||
Group {
|
||||
if let url = video.thumbnailURL(quality: quality) {
|
||||
AsyncImage(url: url) { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(minWidth: minWidth, maxWidth: maxWidth, minHeight: minHeight, maxHeight: maxHeight)
|
||||
} placeholder: {
|
||||
ProgressView()
|
||||
}
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
} else {
|
||||
Image(systemName: "exclamationmark.square")
|
||||
}
|
||||
}
|
||||
.frame(minWidth: minWidth, maxWidth: maxWidth, minHeight: minHeight, maxHeight: maxHeight)
|
||||
}
|
||||
|
||||
func videoDetail(_ text: String, color: Color? = .primary, bold: Bool = false) -> some View {
|
||||
Text(text)
|
||||
.fontWeight(bold ? .bold : .regular)
|
||||
#if os(tvOS)
|
||||
.foregroundColor(color)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
#elseif os(iOS) || os(macOS)
|
||||
.foregroundColor(focused ? .white : color)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoListRowPreview: PreviewProvider {
|
||||
static var previews: some View {
|
||||
List {
|
||||
VideoListRowView(video: Video.fixture)
|
||||
VideoListRowView(video: Video.fixtureUpcomingWithoutPublishedOrViews)
|
||||
VideoListRowView(video: Video.fixtureLiveWithoutPublishedOrViews)
|
||||
}
|
||||
.frame(maxWidth: 400)
|
||||
|
||||
#if os(iOS)
|
||||
List {
|
||||
VideoListRowView(video: Video.fixture)
|
||||
VideoListRowView(video: Video.fixtureUpcomingWithoutPublishedOrViews)
|
||||
VideoListRowView(video: Video.fixtureLiveWithoutPublishedOrViews)
|
||||
}
|
||||
.environment(\.verticalSizeClass, .compact)
|
||||
.frame(maxWidth: 800)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ struct VideosCellsView: View {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
LazyVGrid(columns: items, alignment: .center) {
|
||||
ForEach(videos) { video in
|
||||
VideoCellView(video: video)
|
||||
VideoView(video: video)
|
||||
.contextMenu { VideoContextMenuView(video: video) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideosListView: View {
|
||||
var videos: [Video]
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
List {
|
||||
ForEach(videos) { video in
|
||||
VideoListRowView(video: video)
|
||||
.contextMenu { VideoContextMenuView(video: video) }
|
||||
#if os(tvOS)
|
||||
.listRowInsets(listRowInsets)
|
||||
|
||||
#elseif os(iOS)
|
||||
.listRowInsets(EdgeInsets(.zero))
|
||||
.listRowSeparator(.hidden)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if os(tvOS)
|
||||
.listStyle(GroupedListStyle())
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
var listRowInsets: EdgeInsets {
|
||||
EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30)
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideosView: View {
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
|
||||
@State private var profile = Profile()
|
||||
|
||||
#if os(tvOS)
|
||||
@Default(.layout) var layout
|
||||
#endif
|
||||
|
||||
@Default(.showingAddToPlaylist) var showingAddToPlaylist
|
||||
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var horizontalSizeClass
|
||||
#endif
|
||||
|
||||
var videos: [Video]
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
#if os(tvOS)
|
||||
if layout == .cells {
|
||||
VideosCellsView(videos: videos, columns: self.profile.cellsColumns)
|
||||
} else {
|
||||
VideosListView(videos: videos)
|
||||
}
|
||||
#else
|
||||
VideosListView(videos: videos)
|
||||
#if os(macOS)
|
||||
.frame(minWidth: 400)
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
.fullScreenCover(isPresented: $navigationState.showingVideo) {
|
||||
if let video = navigationState.video {
|
||||
VideoPlayerView(video)
|
||||
}
|
||||
}
|
||||
.fullScreenCover(isPresented: $showingAddToPlaylist) {
|
||||
AddToPlaylistView()
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user