Subscriptions view

This commit is contained in:
Arkadiusz Fal 2021-06-12 00:49:42 +02:00
parent 4af395d788
commit 65e5f0f426
10 changed files with 78 additions and 60 deletions

View File

@ -16,6 +16,10 @@ struct PopularVideosView: View {
} }
var videos: [Video] { var videos: [Video] {
if (provider.videos.isEmpty) {
provider.load()
}
return provider.videos return provider.videos
} }
} }

View File

@ -0,0 +1,21 @@
import SwiftUI
struct SubscriptionsView: View {
@ObservedObject private var provider = SubscriptionVideosProvider()
@ObservedObject var state: AppState
@Binding var tabSelection: TabSelection
var body: some View {
VideosView(state: state, tabSelection: $tabSelection, videos: videos)
.task {
async {
provider.load()
}
}
}
var videos: [Video] {
return provider.videos
}
}

View File

@ -8,7 +8,7 @@ struct VideosView: View {
var videos: [Video] var videos: [Video]
var body: some View { var body: some View {
Group { Section {
List { List {
ForEach(videos) { video in ForEach(videos) { video in
VideoThumbnailView(video: video) VideoThumbnailView(video: video)

View File

@ -2,8 +2,8 @@ import Foundation
class AppState: ObservableObject { class AppState: ObservableObject {
@Published var showingChannel = false @Published var showingChannel = false
@Published var channelID: String? @Published var channelID: String = ""
@Published var channel: String? @Published var channel: String = ""
func openChannel(from video: Video) { func openChannel(from video: Video) {
channel = video.author channel = video.author
@ -13,7 +13,7 @@ class AppState: ObservableObject {
func closeChannel() { func closeChannel() {
showingChannel = false showingChannel = false
channel = nil channel = ""
channelID = nil channelID = ""
} }
} }

View File

@ -4,8 +4,8 @@ import Foundation
class DataProvider: ObservableObject { class DataProvider: ObservableObject {
static let instance = "https://invidious.home.arekf.net" static let instance = "https://invidious.home.arekf.net"
static func request(_ path: String) -> DataRequest { static func request(_ path: String, headers: HTTPHeaders? = nil) -> DataRequest {
AF.request(apiURLString(path)) AF.request(apiURLString(path), headers: headers)
} }
static func apiURLString(_ path: String) -> String { static func apiURLString(_ path: String) -> String {

View File

@ -0,0 +1,23 @@
import Alamofire
import Foundation
import SwiftyJSON
class SubscriptionVideosProvider: DataProvider {
@Published var videos = [Video]()
var sid: String = "RpoS7YPPK2-QS81jJF9z4KSQAjmzsOnMpn84c73-GQ8="
func load() {
let headers = HTTPHeaders([HTTPHeader(name: "Cookie", value: "SID=\(sid)")])
DataProvider.request("auth/feed", headers: headers).responseJSON { response in
switch response.result {
case let .success(value):
if let feedVideos = JSON(value).dictionaryValue["videos"] {
self.videos = feedVideos.arrayValue.map { Video($0) }
}
case let .failure(error):
print(error)
}
}
}
}

View File

@ -23,6 +23,12 @@
37AAF2952674086B007FC770 /* 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 */; }; 37AAF2962674086B007FC770 /* TabSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF2932674086B007FC770 /* TabSelection.swift */; };
37AAF29A26740A01007FC770 /* VideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29926740A01007FC770 /* VideosView.swift */; }; 37AAF29A26740A01007FC770 /* VideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29926740A01007FC770 /* VideosView.swift */; };
37AAF29C26741B5F007FC770 /* SubscriptionVideosProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29B26741B5F007FC770 /* SubscriptionVideosProvider.swift */; };
37AAF29D26741B5F007FC770 /* SubscriptionVideosProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29B26741B5F007FC770 /* SubscriptionVideosProvider.swift */; };
37AAF29E26741B5F007FC770 /* SubscriptionVideosProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29B26741B5F007FC770 /* SubscriptionVideosProvider.swift */; };
37AAF2A026741C97007FC770 /* SubscriptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29F26741C97007FC770 /* SubscriptionsView.swift */; };
37AAF2A126741C97007FC770 /* SubscriptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29F26741C97007FC770 /* SubscriptionsView.swift */; };
37AAF2A226741C97007FC770 /* SubscriptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF29F26741C97007FC770 /* SubscriptionsView.swift */; };
37D4B0D92671614900C925CA /* Tests_iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D4B0D82671614900C925CA /* Tests_iOS.swift */; }; 37D4B0D92671614900C925CA /* Tests_iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D4B0D82671614900C925CA /* Tests_iOS.swift */; };
37D4B0E32671614900C925CA /* Tests_macOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D4B0E22671614900C925CA /* Tests_macOS.swift */; }; 37D4B0E32671614900C925CA /* Tests_macOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D4B0E22671614900C925CA /* Tests_macOS.swift */; };
37D4B0E42671614900C925CA /* PearvidiousApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D4B0C22671614700C925CA /* PearvidiousApp.swift */; }; 37D4B0E42671614900C925CA /* PearvidiousApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D4B0C22671614700C925CA /* PearvidiousApp.swift */; };
@ -89,6 +95,8 @@
37AAF28F26740715007FC770 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; }; 37AAF28F26740715007FC770 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
37AAF2932674086B007FC770 /* TabSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabSelection.swift; sourceTree = "<group>"; }; 37AAF2932674086B007FC770 /* TabSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabSelection.swift; sourceTree = "<group>"; };
37AAF29926740A01007FC770 /* VideosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideosView.swift; sourceTree = "<group>"; }; 37AAF29926740A01007FC770 /* VideosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideosView.swift; sourceTree = "<group>"; };
37AAF29B26741B5F007FC770 /* SubscriptionVideosProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionVideosProvider.swift; sourceTree = "<group>"; };
37AAF29F26741C97007FC770 /* SubscriptionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionsView.swift; sourceTree = "<group>"; };
37D4B0C22671614700C925CA /* PearvidiousApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PearvidiousApp.swift; sourceTree = "<group>"; }; 37D4B0C22671614700C925CA /* PearvidiousApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PearvidiousApp.swift; sourceTree = "<group>"; };
37D4B0C32671614700C925CA /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; 37D4B0C32671614700C925CA /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
37D4B0C42671614800C925CA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 37D4B0C42671614800C925CA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -217,6 +225,7 @@
37D4B159267164AE00C925CA /* Apple TV */ = { 37D4B159267164AE00C925CA /* Apple TV */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
37AAF29F26741C97007FC770 /* SubscriptionsView.swift */,
37AAF27D26737323007FC770 /* PopularVideosView.swift */, 37AAF27D26737323007FC770 /* PopularVideosView.swift */,
37AAF2892673AB89007FC770 /* ChannelView.swift */, 37AAF2892673AB89007FC770 /* ChannelView.swift */,
37AAF27F26737550007FC770 /* SearchView.swift */, 37AAF27F26737550007FC770 /* SearchView.swift */,
@ -242,6 +251,7 @@
children = ( children = (
37AAF28F26740715007FC770 /* AppState.swift */, 37AAF28F26740715007FC770 /* AppState.swift */,
37D4B19626717E1500C925CA /* Video.swift */, 37D4B19626717E1500C925CA /* Video.swift */,
37AAF29B26741B5F007FC770 /* SubscriptionVideosProvider.swift */,
37D4B19226717CE100C925CA /* PopularVideosProvider.swift */, 37D4B19226717CE100C925CA /* PopularVideosProvider.swift */,
37AAF28B2673ABD3007FC770 /* ChannelVideosProvider.swift */, 37AAF28B2673ABD3007FC770 /* ChannelVideosProvider.swift */,
37AAF2812673791F007FC770 /* SearchedVideosProvider.swift */, 37AAF2812673791F007FC770 /* SearchedVideosProvider.swift */,
@ -481,6 +491,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
37D4B19326717CE100C925CA /* PopularVideosProvider.swift in Sources */, 37D4B19326717CE100C925CA /* PopularVideosProvider.swift in Sources */,
37AAF29C26741B5F007FC770 /* SubscriptionVideosProvider.swift in Sources */,
37D4B0E62671614900C925CA /* ContentView.swift in Sources */, 37D4B0E62671614900C925CA /* ContentView.swift in Sources */,
37AAF2822673791F007FC770 /* SearchedVideosProvider.swift in Sources */, 37AAF2822673791F007FC770 /* SearchedVideosProvider.swift in Sources */,
37AAF29026740715007FC770 /* AppState.swift in Sources */, 37AAF29026740715007FC770 /* AppState.swift in Sources */,
@ -488,6 +499,7 @@
37D4B1B02672A01000C925CA /* DataProvider.swift in Sources */, 37D4B1B02672A01000C925CA /* DataProvider.swift in Sources */,
37AAF28C2673ABD3007FC770 /* ChannelVideosProvider.swift in Sources */, 37AAF28C2673ABD3007FC770 /* ChannelVideosProvider.swift in Sources */,
37D4B1B42672A30700C925CA /* VideoDetailsProvider.swift in Sources */, 37D4B1B42672A30700C925CA /* VideoDetailsProvider.swift in Sources */,
37AAF2A026741C97007FC770 /* SubscriptionsView.swift in Sources */,
37D4B19726717E1500C925CA /* Video.swift in Sources */, 37D4B19726717E1500C925CA /* Video.swift in Sources */,
37D4B0E42671614900C925CA /* PearvidiousApp.swift in Sources */, 37D4B0E42671614900C925CA /* PearvidiousApp.swift in Sources */,
); );
@ -498,6 +510,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
37D4B19426717CE100C925CA /* PopularVideosProvider.swift in Sources */, 37D4B19426717CE100C925CA /* PopularVideosProvider.swift in Sources */,
37AAF29D26741B5F007FC770 /* SubscriptionVideosProvider.swift in Sources */,
37D4B0E72671614900C925CA /* ContentView.swift in Sources */, 37D4B0E72671614900C925CA /* ContentView.swift in Sources */,
37AAF2832673791F007FC770 /* SearchedVideosProvider.swift in Sources */, 37AAF2832673791F007FC770 /* SearchedVideosProvider.swift in Sources */,
37AAF29126740715007FC770 /* AppState.swift in Sources */, 37AAF29126740715007FC770 /* AppState.swift in Sources */,
@ -505,6 +518,7 @@
37D4B1B12672A01000C925CA /* DataProvider.swift in Sources */, 37D4B1B12672A01000C925CA /* DataProvider.swift in Sources */,
37AAF28D2673ABD3007FC770 /* ChannelVideosProvider.swift in Sources */, 37AAF28D2673ABD3007FC770 /* ChannelVideosProvider.swift in Sources */,
37D4B1B52672A30700C925CA /* VideoDetailsProvider.swift in Sources */, 37D4B1B52672A30700C925CA /* VideoDetailsProvider.swift in Sources */,
37AAF2A126741C97007FC770 /* SubscriptionsView.swift in Sources */,
37D4B19826717E1500C925CA /* Video.swift in Sources */, 37D4B19826717E1500C925CA /* Video.swift in Sources */,
37D4B0E52671614900C925CA /* PearvidiousApp.swift in Sources */, 37D4B0E52671614900C925CA /* PearvidiousApp.swift in Sources */,
); );
@ -532,6 +546,7 @@
files = ( files = (
37AAF28026737550007FC770 /* SearchView.swift in Sources */, 37AAF28026737550007FC770 /* SearchView.swift in Sources */,
37D4B19526717CE100C925CA /* PopularVideosProvider.swift in Sources */, 37D4B19526717CE100C925CA /* PopularVideosProvider.swift in Sources */,
37AAF29E26741B5F007FC770 /* SubscriptionVideosProvider.swift in Sources */,
37D4B1842671684E00C925CA /* PlayerView.swift in Sources */, 37D4B1842671684E00C925CA /* PlayerView.swift in Sources */,
37D4B1802671650A00C925CA /* PearvidiousApp.swift in Sources */, 37D4B1802671650A00C925CA /* PearvidiousApp.swift in Sources */,
37D4B1B22672A01000C925CA /* DataProvider.swift in Sources */, 37D4B1B22672A01000C925CA /* DataProvider.swift in Sources */,
@ -544,6 +559,7 @@
37AAF28A2673AB89007FC770 /* ChannelView.swift in Sources */, 37AAF28A2673AB89007FC770 /* ChannelView.swift in Sources */,
37AAF28E2673ABD3007FC770 /* ChannelVideosProvider.swift in Sources */, 37AAF28E2673ABD3007FC770 /* ChannelVideosProvider.swift in Sources */,
37D4B19926717E1500C925CA /* Video.swift in Sources */, 37D4B19926717E1500C925CA /* Video.swift in Sources */,
37AAF2A226741C97007FC770 /* SubscriptionsView.swift in Sources */,
37D4B1812671653A00C925CA /* ContentView.swift in Sources */, 37D4B1812671653A00C925CA /* ContentView.swift in Sources */,
37AAF2842673791F007FC770 /* SearchedVideosProvider.swift in Sources */, 37AAF2842673791F007FC770 /* SearchedVideosProvider.swift in Sources */,
); );

View File

@ -3,54 +3,4 @@
uuid = "E30DA302-B258-4C14-8808-5E4CE238A4FF" uuid = "E30DA302-B258-4C14-8808-5E4CE238A4FF"
type = "1" type = "1"
version = "2.0"> version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "6F232B4B-8357-4EFC-81EA-3D0D2ADA975C"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Shared/VideoProvider.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "18"
endingLineNumber = "18"
landmarkName = "init()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "6611D00B-216F-4D19-8477-50314F55BDD4"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Shared/VideoDetailsProvider.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "19"
endingLineNumber = "19"
landmarkName = "load()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "14CD2BD6-9051-4DD5-9A50-EB8B50C5E6C0"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Shared/PlayerView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "19"
endingLineNumber = "19"
landmarkName = "body"
landmarkType = "24">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket> </Bucket>

View File

@ -3,18 +3,22 @@ import SwiftUI
struct ContentView: View { struct ContentView: View {
@StateObject var state = AppState() @StateObject var state = AppState()
@State var tabSelection: TabSelection = .popular @State var tabSelection: TabSelection = .subscriptions
var body: some View { var body: some View {
NavigationView { NavigationView {
TabView(selection: $tabSelection) { TabView(selection: $tabSelection) {
SubscriptionsView(state: state, tabSelection: $tabSelection)
.tabItem { Text("Subscriptions") }
.tag(TabSelection.subscriptions)
PopularVideosView(state: state, tabSelection: $tabSelection) PopularVideosView(state: state, tabSelection: $tabSelection)
.tabItem { Text("Popular") } .tabItem { Text("Popular") }
.tag(TabSelection.popular) .tag(TabSelection.popular)
if state.showingChannel { if state.showingChannel {
ChannelView(state: state, tabSelection: $tabSelection) ChannelView(state: state, tabSelection: $tabSelection)
.tabItem { Text("\(state.channel!) Channel") } .tabItem { Text("\(state.channel) Channel") }
.tag(TabSelection.channel) .tag(TabSelection.channel)
} }

View File

@ -1,5 +1,5 @@
import Foundation import Foundation
enum TabSelection { enum TabSelection {
case popular, channel, search case subscriptions, popular, channel, search
} }