From 66c8b647bfa82965fffa9221ec6356f6d054bbc0 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 1 Aug 2021 23:25:50 +0200 Subject: [PATCH] Minor code style fixes, remove unneeded views --- Apple TV/TVNavigationView.swift | 9 ++++++- Apple TV/VideoLoading.swift | 19 -------------- Fixtures/Video+Fixtures.swift | 4 ++- Pearvidious.xcodeproj/project.pbxproj | 12 --------- Shared/AppSidebarNavigation.swift | 6 +++++ Shared/PlayerViewController.swift | 8 ++---- Shared/TabSelection.swift | 6 ----- Shared/VideoPlayerView.swift | 36 ++++++++------------------- 8 files changed, 30 insertions(+), 70 deletions(-) delete mode 100644 Apple TV/VideoLoading.swift delete mode 100644 Shared/TabSelection.swift diff --git a/Apple TV/TVNavigationView.swift b/Apple TV/TVNavigationView.swift index 7b89162f..c6810a37 100644 --- a/Apple TV/TVNavigationView.swift +++ b/Apple TV/TVNavigationView.swift @@ -6,6 +6,8 @@ struct TVNavigationView: View { @State private var showingOptions = false + @Default(.showingAddToPlaylist) var showingAddToPlaylist + var body: some View { NavigationView { TabView(selection: $navigationState.tabSelection) { @@ -30,6 +32,7 @@ struct TVNavigationView: View { .tag(TabSelection.search) } .fullScreenCover(isPresented: $showingOptions) { OptionsView() } + .fullScreenCover(isPresented: $showingAddToPlaylist) { AddToPlaylistView() } .fullScreenCover(isPresented: $navigationState.showingVideoDetails) { if let video = navigationState.video { VideoDetailsView(video) @@ -42,7 +45,11 @@ struct TVNavigationView: View { ChannelView(id: channel.id) } } - + .fullScreenCover(isPresented: $navigationState.showingVideo) { + if let video = navigationState.video { + VideoPlayerView(video) + } + } .onPlayPauseCommand { showingOptions.toggle() } } } diff --git a/Apple TV/VideoLoading.swift b/Apple TV/VideoLoading.swift deleted file mode 100644 index 044f4723..00000000 --- a/Apple TV/VideoLoading.swift +++ /dev/null @@ -1,19 +0,0 @@ -import SwiftUI - -struct VideoLoading: View { - var video: Video - - var body: some View { - VStack { - Spacer() - - VStack { - Text(video.title) - - Text("Loading...") - } - - Spacer() - } - } -} diff --git a/Fixtures/Video+Fixtures.swift b/Fixtures/Video+Fixtures.swift index 283f8460..2a44bc2a 100644 --- a/Fixtures/Video+Fixtures.swift +++ b/Fixtures/Video+Fixtures.swift @@ -1,9 +1,11 @@ +import Foundation + extension Video { static var fixture: Video { let id = "D2sxamzaHkM" return Video( - id: id, + id: UUID().uuidString, title: "Relaxing Piano Music", author: "Fancy Videotuber", length: 582, diff --git a/Pearvidious.xcodeproj/project.pbxproj b/Pearvidious.xcodeproj/project.pbxproj index 7fe2c362..ca9e3364 100644 --- a/Pearvidious.xcodeproj/project.pbxproj +++ b/Pearvidious.xcodeproj/project.pbxproj @@ -30,7 +30,6 @@ 372915E62687E3B900F5A35B /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372915E52687E3B900F5A35B /* Defaults.swift */; }; 372915E72687E3B900F5A35B /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372915E52687E3B900F5A35B /* Defaults.swift */; }; 372915E82687E3B900F5A35B /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372915E52687E3B900F5A35B /* Defaults.swift */; }; - 372F954A26A4D27000502766 /* VideoLoading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372F954926A4D0C900502766 /* VideoLoading.swift */; }; 373CFABE26966148003CB2C6 /* CoverSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373CFABD26966115003CB2C6 /* CoverSectionView.swift */; }; 373CFABF26966149003CB2C6 /* CoverSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373CFABD26966115003CB2C6 /* CoverSectionView.swift */; }; 373CFAC026966149003CB2C6 /* CoverSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373CFABD26966115003CB2C6 /* CoverSectionView.swift */; }; @@ -103,9 +102,6 @@ 37AAF29026740715007FC770 /* Channel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF28F26740715007FC770 /* Channel.swift */; }; 37AAF29126740715007FC770 /* Channel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF28F26740715007FC770 /* Channel.swift */; }; 37AAF29226740715007FC770 /* Channel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF28F26740715007FC770 /* Channel.swift */; }; - 37AAF2942674086B007FC770 /* TabSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF2932674086B007FC770 /* TabSelection.swift */; }; - 37AAF2952674086B007FC770 /* TabSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF2932674086B007FC770 /* TabSelection.swift */; }; - 37AAF2962674086B007FC770 /* TabSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF2932674086B007FC770 /* TabSelection.swift */; }; 37AAF29A26740A01007FC770 /* VideosListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29926740A01007FC770 /* VideosListView.swift */; }; 37AAF2A026741C97007FC770 /* SubscriptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29F26741C97007FC770 /* SubscriptionsView.swift */; }; 37AAF2A126741C97007FC770 /* SubscriptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29F26741C97007FC770 /* SubscriptionsView.swift */; }; @@ -218,7 +214,6 @@ 37141672267A8E10006CA35D /* Country.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Country.swift; sourceTree = ""; }; 371F2F19269B43D300E4A7AB /* NavigationState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationState.swift; sourceTree = ""; }; 372915E52687E3B900F5A35B /* Defaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Defaults.swift; sourceTree = ""; }; - 372F954926A4D0C900502766 /* VideoLoading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoLoading.swift; sourceTree = ""; }; 373CFABD26966115003CB2C6 /* CoverSectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoverSectionView.swift; sourceTree = ""; }; 373CFAC126966159003CB2C6 /* CoverSectionRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoverSectionRowView.swift; sourceTree = ""; }; 373CFAC52696617C003CB2C6 /* SearchOptionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchOptionsView.swift; sourceTree = ""; }; @@ -240,7 +235,6 @@ 37AAF27F26737550007FC770 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = ""; }; 37AAF2892673AB89007FC770 /* ChannelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelView.swift; sourceTree = ""; }; 37AAF28F26740715007FC770 /* Channel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Channel.swift; sourceTree = ""; }; - 37AAF2932674086B007FC770 /* TabSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabSelection.swift; sourceTree = ""; }; 37AAF29926740A01007FC770 /* VideosListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideosListView.swift; sourceTree = ""; }; 37AAF29F26741C97007FC770 /* SubscriptionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionsView.swift; sourceTree = ""; }; 37B17D9F268A1F25006AEE9B /* VideoContextMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoContextMenuView.swift; sourceTree = ""; }; @@ -411,7 +405,6 @@ 37AAF27D26737323007FC770 /* PopularView.swift */, 37AAF27F26737550007FC770 /* SearchView.swift */, 37AAF29F26741C97007FC770 /* SubscriptionsView.swift */, - 37AAF2932674086B007FC770 /* TabSelection.swift */, 3705B17F267B4DFB00704544 /* TrendingCountrySelection.swift */, 3714166E267A8ACC006CA35D /* TrendingView.swift */, 37BE0BCE26A0E2D50092E2DB /* VideoPlayerView.swift */, @@ -466,7 +459,6 @@ 37BAB54B269B39FD00E75ED1 /* TVNavigationView.swift */, 37B17D9F268A1F25006AEE9B /* VideoContextMenuView.swift */, 37B17DA3268A285E006AEE9B /* VideoDetailsView.swift */, - 372F954926A4D0C900502766 /* VideoLoading.swift */, 37F4AE7126828F0900BD60EA /* VideosCellsView.swift */, 37D4B15E267164AF00C925CA /* Assets.xcassets */, 37D4B1AE26729DEB00C925CA /* Info.plist */, @@ -781,7 +773,6 @@ 377FC7E3267A084A00A6BBAF /* VideoView.swift in Sources */, 37AAF29026740715007FC770 /* Channel.swift in Sources */, 3748186A26A764FB0084E870 /* Thumbnail+Fixtures.swift in Sources */, - 37AAF2942674086B007FC770 /* TabSelection.swift in Sources */, 377FC7E5267A084E00A6BBAF /* SearchView.swift in Sources */, 376578912685490700D4EA09 /* PlaylistsView.swift in Sources */, 377A20A92693C9A2002842B8 /* TypedContentAccessors.swift in Sources */, @@ -829,7 +820,6 @@ 37AAF29126740715007FC770 /* Channel.swift in Sources */, 373CFAC726966187003CB2C6 /* SearchOptionsView.swift in Sources */, 37BD07BC2698AB60003EBB87 /* AppSidebarNavigation.swift in Sources */, - 37AAF2952674086B007FC770 /* TabSelection.swift in Sources */, 3748186F26A769D60084E870 /* DetailBadge.swift in Sources */, 372915E72687E3B900F5A35B /* Defaults.swift in Sources */, 376578922685490700D4EA09 /* PlaylistsView.swift in Sources */, @@ -910,7 +900,6 @@ 37BE0BD126A0E2D50092E2DB /* VideoPlayerView.swift in Sources */, 37AAF27E26737323007FC770 /* PopularView.swift in Sources */, 37AAF29A26740A01007FC770 /* VideosListView.swift in Sources */, - 37AAF2962674086B007FC770 /* TabSelection.swift in Sources */, 37C7A1D7267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */, 376578932685490700D4EA09 /* PlaylistsView.swift in Sources */, 3748186C26A764FB0084E870 /* Thumbnail+Fixtures.swift in Sources */, @@ -919,7 +908,6 @@ 371F2F1C269B43D300E4A7AB /* NavigationState.swift in Sources */, 37B17DA0268A1F89006AEE9B /* VideoContextMenuView.swift in Sources */, 37BE0BD726A1D4A90092E2DB /* PlayerViewController.swift in Sources */, - 372F954A26A4D27000502766 /* VideoLoading.swift in Sources */, 37CEE4C32677B697005A1EFE /* Stream.swift in Sources */, 37BE0BE526A336910092E2DB /* OptionsView.swift in Sources */, 3711404126B206A6005B3555 /* SearchState.swift in Sources */, diff --git a/Shared/AppSidebarNavigation.swift b/Shared/AppSidebarNavigation.swift index 8f92aa46..6330ec1c 100644 --- a/Shared/AppSidebarNavigation.swift +++ b/Shared/AppSidebarNavigation.swift @@ -3,7 +3,13 @@ import SwiftUI import Introspect #endif +typealias TabSelection = AppSidebarNavigation.TabSelection + struct AppSidebarNavigation: View { + enum TabSelection: String { + case subscriptions, popular, trending, playlists, channel, search + } + @EnvironmentObject private var navigationState @State private var didApplyPrimaryViewWorkAround = false diff --git a/Shared/PlayerViewController.swift b/Shared/PlayerViewController.swift index 5de8e49b..1f53ddcc 100644 --- a/Shared/PlayerViewController.swift +++ b/Shared/PlayerViewController.swift @@ -68,13 +68,9 @@ extension PlayerViewController: AVPlayerViewControllerDelegate { func playerViewController( _: AVPlayerViewController, - willBeginFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator + willBeginFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator ) { - coordinator.animate(alongsideTransition: nil) { context in - if !context.isCancelled { - self.playingFullScreen = true - } - } + playingFullScreen = true } func playerViewController( diff --git a/Shared/TabSelection.swift b/Shared/TabSelection.swift deleted file mode 100644 index d8948698..00000000 --- a/Shared/TabSelection.swift +++ /dev/null @@ -1,6 +0,0 @@ -import Defaults -import Foundation - -enum TabSelection: String, DefaultsSerializable { - case subscriptions, popular, trending, playlists, channel, search -} diff --git a/Shared/VideoPlayerView.swift b/Shared/VideoPlayerView.swift index f29c7914..5464e630 100644 --- a/Shared/VideoPlayerView.swift +++ b/Shared/VideoPlayerView.swift @@ -13,37 +13,25 @@ struct VideoPlayerView: View { var video: Video - var player: AVPlayer! - init(_ video: Video) { self.video = video resource.addObserver(store) - - player = AVPlayer() } var body: some View { VStack { - #if os(tvOS) - if store.item == nil { - VideoLoading(video: video) + Player(video: video) + .frame(alignment: .leading) + + #if !os(tvOS) + ScrollView(.vertical) { + VStack(alignment: .leading) { + Text(video.title) + Text(video.author) + } + .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) } #endif - - VStack { - Player(video: video) - .frame(alignment: .leading) - - #if !os(tvOS) - ScrollView(.vertical) { - VStack(alignment: .leading) { - Text(video.title) - Text(video.author) - } - .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) - } - #endif - } } .onAppear { resource.loadIfNeeded() @@ -54,9 +42,7 @@ struct VideoPlayerView: View { navigationState.showingVideoDetails = navigationState.returnToDetails } - #if os(tvOS) - .background(.thinMaterial) - #elseif os(macOS) + #if os(macOS) .navigationTitle(video.title) #elseif os(iOS) .navigationBarTitle(video.title, displayMode: .inline)