From 7c4eee4a44c63154153c05de61bd9249f41d58c8 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 27 Jun 2021 01:29:55 +0200 Subject: [PATCH] Add Defaults library --- Apple TV/ChannelView.swift | 4 +- Apple TV/PlaylistsView.swift | 4 +- Apple TV/PopularVideosView.swift | 4 +- Apple TV/SearchView.swift | 4 +- Apple TV/SubscriptionsView.swift | 4 +- Apple TV/TrendingCountrySelectionView.swift | 23 ++++----- Apple TV/TrendingView.swift | 4 +- Apple TV/VideosListView.swift | 3 +- Apple TV/VideosView.swift | 9 ++-- Apple TV/ViewOptionsView.swift | 41 ++++++++++------ Apple TV/VisualEffectView.swift | 13 ----- Extensions/AVKeyValueStatus+String.swift | 20 -------- Model/Profile.swift | 9 +--- Pearvidious.xcodeproj/project.pbxproj | 47 +++++++++++++------ .../xcshareddata/swiftpm/Package.resolved | 9 ++++ Shared/ContentView.swift | 15 +++--- Shared/Defaults.swift | 6 +++ Shared/ListingLayout.swift | 14 ++++++ Shared/TabSelection.swift | 3 +- 19 files changed, 125 insertions(+), 111 deletions(-) delete mode 100644 Apple TV/VisualEffectView.swift delete mode 100644 Extensions/AVKeyValueStatus+String.swift create mode 100644 Shared/Defaults.swift create mode 100644 Shared/ListingLayout.swift diff --git a/Apple TV/ChannelView.swift b/Apple TV/ChannelView.swift index da64ea3d..74bd3a30 100644 --- a/Apple TV/ChannelView.swift +++ b/Apple TV/ChannelView.swift @@ -4,10 +4,8 @@ struct ChannelView: View { @ObservedObject private var provider = ChannelVideosProvider() @EnvironmentObject private var state: AppState - @Binding var tabSelection: TabSelection - var body: some View { - VideosListView(tabSelection: $tabSelection, videos: videos) + VideosListView(videos: videos) } var listRowInsets: EdgeInsets { diff --git a/Apple TV/PlaylistsView.swift b/Apple TV/PlaylistsView.swift index d46ccdb1..7a82b5e6 100644 --- a/Apple TV/PlaylistsView.swift +++ b/Apple TV/PlaylistsView.swift @@ -3,8 +3,6 @@ import SwiftUI struct PlaylistsView: View { @EnvironmentObject private var state: AppState - @Binding var tabSelection: TabSelection - @ObservedObject private var provider = PlaylistsProvider() @State private var selectedPlaylist: Playlist? @@ -23,7 +21,7 @@ struct PlaylistsView: View { VStack { if selectedPlaylist != nil { - VideosView(tabSelection: $tabSelection, videos: selectedPlaylist!.videos) + VideosView(videos: selectedPlaylist!.videos) } } } diff --git a/Apple TV/PopularVideosView.swift b/Apple TV/PopularVideosView.swift index cffda949..eb29f892 100644 --- a/Apple TV/PopularVideosView.swift +++ b/Apple TV/PopularVideosView.swift @@ -3,10 +3,8 @@ import SwiftUI struct PopularVideosView: View { @ObservedObject private var provider = PopularVideosProvider() - @Binding var tabSelection: TabSelection - var body: some View { - VideosView(tabSelection: $tabSelection, videos: videos) + VideosView(videos: videos) } var videos: [Video] { diff --git a/Apple TV/SearchView.swift b/Apple TV/SearchView.swift index 2baa8dc5..dd0492a9 100644 --- a/Apple TV/SearchView.swift +++ b/Apple TV/SearchView.swift @@ -5,12 +5,10 @@ struct SearchView: View { @EnvironmentObject private var profile: Profile @EnvironmentObject private var state: AppState - @Binding var tabSelection: TabSelection - @State private var query = "" var body: some View { - VideosView(tabSelection: $tabSelection, videos: videos) + VideosView(videos: videos) .environmentObject(state) .environmentObject(profile) .searchable(text: $query) diff --git a/Apple TV/SubscriptionsView.swift b/Apple TV/SubscriptionsView.swift index dff225ee..d77de8c3 100644 --- a/Apple TV/SubscriptionsView.swift +++ b/Apple TV/SubscriptionsView.swift @@ -1,12 +1,10 @@ import SwiftUI struct SubscriptionsView: View { - @Binding var tabSelection: TabSelection - @ObservedObject private var provider = SubscriptionVideosProvider() var body: some View { - VideosView(tabSelection: $tabSelection, videos: videos) + VideosView(videos: videos) } var videos: [Video] { diff --git a/Apple TV/TrendingCountrySelectionView.swift b/Apple TV/TrendingCountrySelectionView.swift index f54cace4..a033364a 100644 --- a/Apple TV/TrendingCountrySelectionView.swift +++ b/Apple TV/TrendingCountrySelectionView.swift @@ -7,23 +7,20 @@ struct TrendingCountrySelectionView: View { @State private var query: String = "" @Binding var selectedCountry: Country - var body: some View { - ZStack { - VisualEffectView(effect: UIBlurEffect(style: .dark)) + @Environment(\.dismiss) private var dismiss - ScrollView(.vertical) { - ForEach(countries) { country in - Button(country.name) { - selectedCountry = country - presentationMode.wrappedValue.dismiss() - } + var body: some View { + ScrollView(.vertical) { + ForEach(countries) { country in + Button(country.name) { + selectedCountry = country + presentationMode.wrappedValue.dismiss() } - .frame(width: 800) } - .searchable(text: $query) + .frame(width: 800) } - .frame(maxWidth: .infinity, maxHeight: .infinity) - .edgesIgnoringSafeArea(.all) + .searchable(text: $query) + .background(.thinMaterial) } var countries: [Country] { diff --git a/Apple TV/TrendingView.swift b/Apple TV/TrendingView.swift index 9975b825..866eeaee 100644 --- a/Apple TV/TrendingView.swift +++ b/Apple TV/TrendingView.swift @@ -3,8 +3,6 @@ import SwiftUI struct TrendingView: View { @EnvironmentObject private var state: AppState - @Binding var tabSelection: TabSelection - @ObservedObject private var videosProvider = TrendingVideosProvider() @SceneStorage("category") var category: TrendingCategory = .default @@ -26,7 +24,7 @@ struct TrendingView: View { } .scaleEffect(0.85) - VideosView(tabSelection: $tabSelection, videos: videos) + VideosView(videos: videos) } } } diff --git a/Apple TV/VideosListView.swift b/Apple TV/VideosListView.swift index 1edb4923..e5901a68 100644 --- a/Apple TV/VideosListView.swift +++ b/Apple TV/VideosListView.swift @@ -1,9 +1,10 @@ +import Defaults import SwiftUI struct VideosListView: View { @EnvironmentObject private var state: AppState - @Binding var tabSelection: TabSelection + @Default(.tabSelection) var tabSelection var videos: [Video] diff --git a/Apple TV/VideosView.swift b/Apple TV/VideosView.swift index ec22bb03..134cc578 100644 --- a/Apple TV/VideosView.swift +++ b/Apple TV/VideosView.swift @@ -1,17 +1,20 @@ +import Defaults import SwiftUI struct VideosView: View { @EnvironmentObject private var profile: Profile - @Binding var tabSelection: TabSelection var videos: [Video] + @Default(.layout) var layout + @Default(.tabSelection) var tabSelection + @State private var showingViewOptions = false var body: some View { Section { - if self.profile.listing == .list { - VideosListView(tabSelection: $tabSelection, videos: videos) + if layout == .list { + VideosListView(videos: videos) } else { VideosCellsView(videos: videos, columns: self.profile.cellsColumns) } diff --git a/Apple TV/ViewOptionsView.swift b/Apple TV/ViewOptionsView.swift index fe1e1099..389fe995 100644 --- a/Apple TV/ViewOptionsView.swift +++ b/Apple TV/ViewOptionsView.swift @@ -1,32 +1,45 @@ +import Defaults import SwiftUI struct ViewOptionsView: View { @EnvironmentObject private var profile: Profile - @Environment(\.presentationMode) private var presentationMode + @Environment(\.dismiss) private var dismiss + @Default(.layout) var layout var body: some View { - ZStack { - VisualEffectView(effect: UIBlurEffect(style: .dark)) - + HStack { VStack { Spacer() - ScrollView(.vertical) { - Button(profile.listing == .list ? "Cells" : "List") { - profile.listing = (profile.listing == .list ? .cells : .list) - presentationMode.wrappedValue.dismiss() + HStack(alignment: .center) { + Spacer() + + VStack { + nextLayoutButton + + Button("Close") { + dismiss() + } } - Button("Close") { - presentationMode.wrappedValue.dismiss() - } - .frame(width: 800) + Spacer() } + Spacer() } + + Spacer() } - .frame(maxWidth: .infinity, maxHeight: .infinity) - .edgesIgnoringSafeArea(.all) + .background(.thinMaterial) + } + + var nextLayoutButton: some View { + Button(layout.next().name, action: nextLayout) + } + + func nextLayout() { + Defaults[.layout] = layout.next() + dismiss() } } diff --git a/Apple TV/VisualEffectView.swift b/Apple TV/VisualEffectView.swift deleted file mode 100644 index 842e6d76..00000000 --- a/Apple TV/VisualEffectView.swift +++ /dev/null @@ -1,13 +0,0 @@ -import SwiftUI - -struct VisualEffectView: UIViewRepresentable { - var effect: UIVisualEffect? - - func makeUIView(context _: UIViewRepresentableContext) -> UIVisualEffectView { - UIVisualEffectView() - } - - func updateUIView(_ uiView: UIVisualEffectView, context _: UIViewRepresentableContext) { - uiView.effect = effect - } -} diff --git a/Extensions/AVKeyValueStatus+String.swift b/Extensions/AVKeyValueStatus+String.swift deleted file mode 100644 index 0e79bb1c..00000000 --- a/Extensions/AVKeyValueStatus+String.swift +++ /dev/null @@ -1,20 +0,0 @@ -import AVFoundation - -extension AVKeyValueStatus { - var string: String { - switch self { - case .unknown: - return "unknown" - case .loading: - return "loading" - case .loaded: - return "loaded" - case .failed: - return "failed" - case .cancelled: - return "cancelled" - @unknown default: - return "unknown default" - } - } -} diff --git a/Model/Profile.swift b/Model/Profile.swift index 38d05756..c83f2772 100644 --- a/Model/Profile.swift +++ b/Model/Profile.swift @@ -1,22 +1,17 @@ +import Defaults import Foundation final class Profile: ObservableObject { - var defaultStreamResolution: DefaultStreamResolution = .hd720pFirstThenBest + var defaultStreamResolution: DefaultStreamResolution = .hd720p var skippedSegmentsCategories = [String]() // SponsorBlockSegmentsProvider.categories // var sid = "B3_WzklziGu8JKefihLrCsTNavdj73KMiPUBfN5HW2M=" var sid = "RpoS7YPPK2-QS81jJF9z4KSQAjmzsOnMpn84c73-GQ8=" - @Published var listing = VideoListing.cells - var cellsColumns = 3 } -enum VideoListing: String { - case list, cells -} - enum DefaultStreamResolution: String { case hd720pFirstThenBest, hd1080p, hd720p, sd480p, sd360p, sd240p, sd144p diff --git a/Pearvidious.xcodeproj/project.pbxproj b/Pearvidious.xcodeproj/project.pbxproj index be39b345..b9d97d5b 100644 --- a/Pearvidious.xcodeproj/project.pbxproj +++ b/Pearvidious.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 3705B17C267B4D9A00704544 /* VisualEffectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705B17B267B4D9A00704544 /* VisualEffectView.swift */; }; 3705B180267B4DFB00704544 /* TrendingCountrySelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705B17F267B4DFB00704544 /* TrendingCountrySelectionView.swift */; }; 3705B182267B4E4900704544 /* TrendingCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705B181267B4E4900704544 /* TrendingCategory.swift */; }; 3705B183267B4E4900704544 /* TrendingCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705B181267B4E4900704544 /* TrendingCategory.swift */; }; @@ -30,6 +29,13 @@ 3714167F267AB55D006CA35D /* TrendingVideosProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3714167E267AB55D006CA35D /* TrendingVideosProvider.swift */; }; 37141680267AB55D006CA35D /* TrendingVideosProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3714167E267AB55D006CA35D /* TrendingVideosProvider.swift */; }; 37141681267AB55D006CA35D /* TrendingVideosProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3714167E267AB55D006CA35D /* TrendingVideosProvider.swift */; }; + 372915E42687E33E00F5A35B /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = 372915E32687E33E00F5A35B /* Defaults */; }; + 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 */; }; + 372915EA2687EBA500F5A35B /* ListingLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372915E92687EBA500F5A35B /* ListingLayout.swift */; }; + 372915EB2687EBA500F5A35B /* ListingLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372915E92687EBA500F5A35B /* ListingLayout.swift */; }; + 372915EC2687EBA500F5A35B /* ListingLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372915E92687EBA500F5A35B /* ListingLayout.swift */; }; 3741B5302676213400125C5E /* PlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3741B52F2676213400125C5E /* PlayerViewController.swift */; }; 376578852685429C00D4EA09 /* CaseIterable+Next.swift in Sources */ = {isa = PBXBuildFile; fileRef = 376578842685429C00D4EA09 /* CaseIterable+Next.swift */; }; 376578862685429C00D4EA09 /* CaseIterable+Next.swift in Sources */ = {isa = PBXBuildFile; fileRef = 376578842685429C00D4EA09 /* CaseIterable+Next.swift */; }; @@ -99,14 +105,10 @@ 37C7A1D5267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */; }; 37C7A1D6267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */; }; 37C7A1D7267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */; }; - 37C7A1D9267CACE60010EAD6 /* VisualEffectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705B17B267B4D9A00704544 /* VisualEffectView.swift */; }; 37C7A1DA267CACF50010EAD6 /* TrendingCountrySelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3705B17F267B4DFB00704544 /* TrendingCountrySelectionView.swift */; }; 37C7A1DC267CE9D90010EAD6 /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1DB267CE9D90010EAD6 /* Profile.swift */; }; 37C7A1DD267CE9D90010EAD6 /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1DB267CE9D90010EAD6 /* Profile.swift */; }; 37C7A1DE267CE9D90010EAD6 /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1DB267CE9D90010EAD6 /* Profile.swift */; }; - 37C7A9042679059200E721B4 /* AVKeyValueStatus+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A9032679059200E721B4 /* AVKeyValueStatus+String.swift */; }; - 37C7A905267905AE00E721B4 /* AVKeyValueStatus+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A9032679059200E721B4 /* AVKeyValueStatus+String.swift */; }; - 37C7A906267905AF00E721B4 /* AVKeyValueStatus+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A9032679059200E721B4 /* AVKeyValueStatus+String.swift */; }; 37CEE4B52677B628005A1EFE /* StreamType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CEE4B42677B628005A1EFE /* StreamType.swift */; }; 37CEE4B62677B628005A1EFE /* StreamType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CEE4B42677B628005A1EFE /* StreamType.swift */; }; 37CEE4B72677B628005A1EFE /* StreamType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CEE4B42677B628005A1EFE /* StreamType.swift */; }; @@ -189,7 +191,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 3705B17B267B4D9A00704544 /* VisualEffectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisualEffectView.swift; sourceTree = ""; }; 3705B17F267B4DFB00704544 /* TrendingCountrySelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendingCountrySelectionView.swift; sourceTree = ""; }; 3705B181267B4E4900704544 /* TrendingCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendingCategory.swift; sourceTree = ""; }; 371231832683E62F0000B307 /* VideosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideosView.swift; sourceTree = ""; }; @@ -198,6 +199,8 @@ 37141672267A8E10006CA35D /* Country.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Country.swift; sourceTree = ""; }; 3714167A267AA1CF006CA35D /* TrendingCountriesProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendingCountriesProvider.swift; sourceTree = ""; }; 3714167E267AB55D006CA35D /* TrendingVideosProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendingVideosProvider.swift; sourceTree = ""; }; + 372915E52687E3B900F5A35B /* Defaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Defaults.swift; sourceTree = ""; }; + 372915E92687EBA500F5A35B /* ListingLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListingLayout.swift; sourceTree = ""; }; 3741B52F2676213400125C5E /* PlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerViewController.swift; sourceTree = ""; }; 376578842685429C00D4EA09 /* CaseIterable+Next.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CaseIterable+Next.swift"; sourceTree = ""; }; 376578882685471400D4EA09 /* Playlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Playlist.swift; sourceTree = ""; }; @@ -217,7 +220,6 @@ 37B76E95268747C900CE5671 /* ViewOptionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewOptionsView.swift; sourceTree = ""; }; 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SponsorBlockSegment.swift; sourceTree = ""; }; 37C7A1DB267CE9D90010EAD6 /* Profile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profile.swift; sourceTree = ""; }; - 37C7A9032679059200E721B4 /* AVKeyValueStatus+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVKeyValueStatus+String.swift"; sourceTree = ""; }; 37CEE4B42677B628005A1EFE /* StreamType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamType.swift; sourceTree = ""; }; 37CEE4B82677B63F005A1EFE /* StreamResolution.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamResolution.swift; sourceTree = ""; }; 37CEE4BC2677B670005A1EFE /* AudioVideoStream.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioVideoStream.swift; sourceTree = ""; }; @@ -291,6 +293,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 372915E42687E33E00F5A35B /* Defaults in Frameworks */, 37D4B1AD2672580400C925CA /* URLImageStore in Frameworks */, 37D4B19D2671817900C925CA /* SwiftyJSON in Frameworks */, 37D4B1AB2672580400C925CA /* URLImage in Frameworks */, @@ -319,7 +322,6 @@ 37C7A9022679058300E721B4 /* Extensions */ = { isa = PBXGroup; children = ( - 37C7A9032679059200E721B4 /* AVKeyValueStatus+String.swift */, 376578842685429C00D4EA09 /* CaseIterable+Next.swift */, ); path = Extensions; @@ -345,9 +347,11 @@ children = ( 37D4B0C32671614700C925CA /* ContentView.swift */, 37141672267A8E10006CA35D /* Country.swift */, + 372915E52687E3B900F5A35B /* Defaults.swift */, 37D4B0C22671614700C925CA /* PearvidiousApp.swift */, 37AAF2932674086B007FC770 /* TabSelection.swift */, 37D4B0C42671614800C925CA /* Assets.xcassets */, + 372915E92687EBA500F5A35B /* ListingLayout.swift */, ); path = Shared; sourceTree = ""; @@ -400,7 +404,6 @@ 37AAF29926740A01007FC770 /* VideosListView.swift */, 371231832683E62F0000B307 /* VideosView.swift */, 37B76E95268747C900CE5671 /* ViewOptionsView.swift */, - 3705B17B267B4D9A00704544 /* VisualEffectView.swift */, 37D4B15E267164AF00C925CA /* Assets.xcassets */, 37D4B1AE26729DEB00C925CA /* Info.plist */, ); @@ -550,6 +553,7 @@ 37D4B1AA2672580400C925CA /* URLImage */, 37D4B1AC2672580400C925CA /* URLImageStore */, 37B767DF2678C5BF0098BAA8 /* Logging */, + 372915E32687E33E00F5A35B /* Defaults */, ); productName = Pearvidious; productReference = 37D4B158267164AE00C925CA /* Pearvidious (Apple TV).app */; @@ -620,6 +624,7 @@ 37D4B19B2671817900C925CA /* XCRemoteSwiftPackageReference "SwiftyJSON" */, 37D4B1A92672580400C925CA /* XCRemoteSwiftPackageReference "url-image" */, 37B767DE2678C5BF0098BAA8 /* XCRemoteSwiftPackageReference "swift-log" */, + 372915E22687E33E00F5A35B /* XCRemoteSwiftPackageReference "Defaults" */, ); productRefGroup = 37D4B0CA2671614900C925CA /* Products */; projectDirPath = ""; @@ -701,7 +706,6 @@ 37CEE4C12677B697005A1EFE /* Stream.swift in Sources */, 37F4AE7226828F0900BD60EA /* VideosCellsView.swift in Sources */, 376578852685429C00D4EA09 /* CaseIterable+Next.swift in Sources */, - 37C7A1D9267CACE60010EAD6 /* VisualEffectView.swift in Sources */, 37D4B0E62671614900C925CA /* ContentView.swift in Sources */, 377FC7DC267A081800A6BBAF /* PopularVideosView.swift in Sources */, 371231842683E62F0000B307 /* VideosView.swift in Sources */, @@ -723,13 +727,14 @@ 376578912685490700D4EA09 /* PlaylistsView.swift in Sources */, 377FC7E1267A082600A6BBAF /* ChannelView.swift in Sources */, 37C7A1D5267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */, - 37C7A9042679059200E721B4 /* AVKeyValueStatus+String.swift in Sources */, 37B767DB2677C3CA0098BAA8 /* PlayerState.swift in Sources */, 37D4B1B42672A30700C925CA /* VideoDetailsProvider.swift in Sources */, + 372915EA2687EBA500F5A35B /* ListingLayout.swift in Sources */, 37141673267A8E10006CA35D /* Country.swift in Sources */, 37AAF2A026741C97007FC770 /* SubscriptionsView.swift in Sources */, 3714167B267AA1CF006CA35D /* TrendingCountriesProvider.swift in Sources */, 377FC7DF267A082200A6BBAF /* VideosListView.swift in Sources */, + 372915E62687E3B900F5A35B /* Defaults.swift in Sources */, 37D4B19726717E1500C925CA /* Video.swift in Sources */, 37B76E96268747C900CE5671 /* ViewOptionsView.swift in Sources */, 37D4B0E42671614900C925CA /* PearvidiousApp.swift in Sources */, @@ -751,6 +756,7 @@ 37CEE4C22677B697005A1EFE /* Stream.swift in Sources */, 3765788E2685487700D4EA09 /* PlaylistsProvider.swift in Sources */, 37D4B0E72671614900C925CA /* ContentView.swift in Sources */, + 372915EB2687EBA500F5A35B /* ListingLayout.swift in Sources */, 377FC7DD267A081A00A6BBAF /* PopularVideosView.swift in Sources */, 37141680267AB55D006CA35D /* TrendingVideosProvider.swift in Sources */, 3705B183267B4E4900704544 /* TrendingCategory.swift in Sources */, @@ -762,6 +768,7 @@ 3765788A2685471400D4EA09 /* Playlist.swift in Sources */, 37AAF29126740715007FC770 /* AppState.swift in Sources */, 37AAF2952674086B007FC770 /* TabSelection.swift in Sources */, + 372915E72687E3B900F5A35B /* Defaults.swift in Sources */, 376578922685490700D4EA09 /* PlaylistsView.swift in Sources */, 37D4B1B12672A01000C925CA /* DataProvider.swift in Sources */, 37AAF28D2673ABD3007FC770 /* ChannelVideosProvider.swift in Sources */, @@ -774,7 +781,6 @@ 371231862683E7820000B307 /* VideosView.swift in Sources */, 37C7A1D6267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */, 37C7A1DD267CE9D90010EAD6 /* Profile.swift in Sources */, - 37C7A906267905AF00E721B4 /* AVKeyValueStatus+String.swift in Sources */, 37B767DC2677C3CA0098BAA8 /* PlayerState.swift in Sources */, 37D4B1B52672A30700C925CA /* VideoDetailsProvider.swift in Sources */, 37141674267A8E10006CA35D /* Country.swift in Sources */, @@ -827,11 +833,9 @@ 37AAF29226740715007FC770 /* AppState.swift in Sources */, 37EAD86D267B9C5600D9E01B /* SponsorBlockSegmentsProvider.swift in Sources */, 3765788B2685471400D4EA09 /* Playlist.swift in Sources */, - 3705B17C267B4D9A00704544 /* VisualEffectView.swift in Sources */, 37C7A1DE267CE9D90010EAD6 /* Profile.swift in Sources */, 3741B5302676213400125C5E /* PlayerViewController.swift in Sources */, 37B767DD2677C3CA0098BAA8 /* PlayerState.swift in Sources */, - 37C7A905267905AE00E721B4 /* AVKeyValueStatus+String.swift in Sources */, 37D4B18E26717B3800C925CA /* VideoListRow.swift in Sources */, 37D4B1B62672A30700C925CA /* VideoDetailsProvider.swift in Sources */, 37AAF27E26737323007FC770 /* PopularVideosView.swift in Sources */, @@ -844,10 +848,12 @@ 37AAF28E2673ABD3007FC770 /* ChannelVideosProvider.swift in Sources */, 3705B180267B4DFB00704544 /* TrendingCountrySelectionView.swift in Sources */, 37141675267A8E10006CA35D /* Country.swift in Sources */, + 372915EC2687EBA500F5A35B /* ListingLayout.swift in Sources */, 37D4B19926717E1500C925CA /* Video.swift in Sources */, 3714167D267AA1CF006CA35D /* TrendingCountriesProvider.swift in Sources */, 3705B184267B4E4900704544 /* TrendingCategory.swift in Sources */, 37AAF2A226741C97007FC770 /* SubscriptionsView.swift in Sources */, + 372915E82687E3B900F5A35B /* Defaults.swift in Sources */, 37D4B1812671653A00C925CA /* ContentView.swift in Sources */, 37B76E98268747C900CE5671 /* ViewOptionsView.swift in Sources */, 37AAF2842673791F007FC770 /* SearchedVideosProvider.swift in Sources */, @@ -1402,6 +1408,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + 372915E22687E33E00F5A35B /* XCRemoteSwiftPackageReference "Defaults" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/sindresorhus/Defaults"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.0.0; + }; + }; 37B767DE2678C5BF0098BAA8 /* XCRemoteSwiftPackageReference "swift-log" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/apple/swift-log.git"; @@ -1437,6 +1451,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 372915E32687E33E00F5A35B /* Defaults */ = { + isa = XCSwiftPackageProductDependency; + package = 372915E22687E33E00F5A35B /* XCRemoteSwiftPackageReference "Defaults" */; + productName = Defaults; + }; 377FC7D2267A080300A6BBAF /* Alamofire */ = { isa = XCSwiftPackageProductDependency; package = 37D4B18F26717C6900C925CA /* XCRemoteSwiftPackageReference "Alamofire" */; diff --git a/Pearvidious.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Pearvidious.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 29d2c81e..9b26e97b 100644 --- a/Pearvidious.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Pearvidious.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -10,6 +10,15 @@ "version": "5.4.3" } }, + { + "package": "Defaults", + "repositoryURL": "https://github.com/sindresorhus/Defaults", + "state": { + "branch": null, + "revision": "63d93f97ad545c8bceb125a8a36175ea705f7cf5", + "version": "5.0.0" + } + }, { "package": "swift-log", "repositoryURL": "https://github.com/apple/swift-log.git", diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift index e0015cc4..59fd231f 100644 --- a/Shared/ContentView.swift +++ b/Shared/ContentView.swift @@ -1,37 +1,38 @@ +import Defaults import SwiftUI struct ContentView: View { @ObservedObject private var state = AppState() @ObservedObject private var profile = Profile() - @SceneStorage("tabSelection") var tabSelection = TabSelection.subscriptions + @Default(.tabSelection) var tabSelection var body: some View { NavigationView { TabView(selection: $tabSelection) { - SubscriptionsView(tabSelection: $tabSelection) + SubscriptionsView() .tabItem { Text("Subscriptions") } .tag(TabSelection.subscriptions) - PopularVideosView(tabSelection: $tabSelection) + PopularVideosView() .tabItem { Text("Popular") } .tag(TabSelection.popular) if state.showingChannel { - ChannelView(tabSelection: $tabSelection) + ChannelView() .tabItem { Text("\(state.channel) Channel") } .tag(TabSelection.channel) } - TrendingView(tabSelection: $tabSelection) + TrendingView() .tabItem { Text("Trending") } .tag(TabSelection.trending) - PlaylistsView(tabSelection: $tabSelection) + PlaylistsView() .tabItem { Text("Playlists") } .tag(TabSelection.playlists) - SearchView(tabSelection: $tabSelection) + SearchView() .tabItem { Image(systemName: "magnifyingglass") } .tag(TabSelection.search) } diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift new file mode 100644 index 00000000..4b423009 --- /dev/null +++ b/Shared/Defaults.swift @@ -0,0 +1,6 @@ +import Defaults + +extension Defaults.Keys { + static let layout = Key("listingLayout", default: .cells) + static let tabSelection = Key("tabSelection", default: .subscriptions) +} diff --git a/Shared/ListingLayout.swift b/Shared/ListingLayout.swift new file mode 100644 index 00000000..b8de89c7 --- /dev/null +++ b/Shared/ListingLayout.swift @@ -0,0 +1,14 @@ +import Defaults + +enum ListingLayout: String, CaseIterable, Defaults.Serializable { + case list, cells + + var name: String { + switch self { + case .list: + return "List" + case .cells: + return "Cells" + } + } +} diff --git a/Shared/TabSelection.swift b/Shared/TabSelection.swift index 0d943749..d8948698 100644 --- a/Shared/TabSelection.swift +++ b/Shared/TabSelection.swift @@ -1,5 +1,6 @@ +import Defaults import Foundation -enum TabSelection: String { +enum TabSelection: String, DefaultsSerializable { case subscriptions, popular, trending, playlists, channel, search }