167 lines
5.0 KiB
Swift
167 lines
5.0 KiB
Swift
//
|
|
// ContentView.swift
|
|
// vrtnu
|
|
//
|
|
// Created by Jens Timmerman on 23/09/2020.
|
|
//
|
|
|
|
import SwiftUI
|
|
import AVKit
|
|
import AVFoundation
|
|
import Combine
|
|
import TVUIKit
|
|
|
|
|
|
struct ContentView: View {
|
|
@ViewBuilder
|
|
var body: some View {
|
|
VRTNuView(vrtNu: VRTNu())
|
|
}
|
|
}
|
|
|
|
struct LoginView: View{
|
|
var vrtNu: VRTNu
|
|
@State private var password: String = ""
|
|
@State private var username: String = ""
|
|
@State var authenticationDidFail: Bool = false
|
|
// needed to update parent view when login was succesful
|
|
@Binding var loginaction: Bool
|
|
|
|
|
|
var body: some View {
|
|
|
|
if authenticationDidFail {
|
|
Text("Information not correct. Try again.")
|
|
.offset(y: -10)
|
|
.foregroundColor(.red)
|
|
}
|
|
TextField("VRTNu username", text: $username)
|
|
SecureField("VRTNu password", text: $password)
|
|
Button("Inloggen", action: {
|
|
|
|
let loginok = vrtNu.login(username: username, password: password)
|
|
if loginok{
|
|
// reload parent view here
|
|
withAnimation {
|
|
self.loginaction.toggle()
|
|
}
|
|
}else{
|
|
authenticationDidFail = true
|
|
}
|
|
})
|
|
}
|
|
}
|
|
struct VRTNuView: View{
|
|
var vrtNu: VRTNu
|
|
var body: some View {
|
|
|
|
NavigationView(){
|
|
List(vrtNu.getShows(), id: \.title){ show in
|
|
NavigationLink(destination: ShowView(show: show)){
|
|
HStack{
|
|
AsyncImage(url: show.imageURL,placeholder: {
|
|
//Image(name: "loading")
|
|
Text("Loading...")
|
|
}, image:{
|
|
Image(uiImage:$0)
|
|
.resizable()
|
|
}).aspectRatio(contentMode: .fit).frame(width: 480, height:300)
|
|
VStack(alignment: .leading){
|
|
Text(show.title)
|
|
.padding()
|
|
Text(show.showURL.absoluteString)
|
|
}
|
|
}
|
|
}
|
|
}.navigationBarTitle("Browse VRT Nu")
|
|
}
|
|
}
|
|
}
|
|
struct ShowView: View {
|
|
var show: Show
|
|
var body: some View {
|
|
NavigationView(){
|
|
List{
|
|
ForEach(show.getSeasons(), id: \.self){ season in
|
|
Section(header: Text(season.seasonName).font(.largeTitle)) {
|
|
ForEach(season.getEpisodes(), id:\.self){ episode in
|
|
NavigationLink(destination: VideoView(episode: episode)){
|
|
HStack{
|
|
AsyncImage(url: episode.imageURL,placeholder: {
|
|
//Image(name: "loading")
|
|
Text("Loading...")
|
|
},image:{Image(uiImage:$0).resizable()
|
|
}).aspectRatio(contentMode: .fit).frame(width: 480, height:300)
|
|
VStack(alignment: .leading){
|
|
Text(episode.title).padding()
|
|
Text(episode.episodeurl)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct VisibleShowView: View {
|
|
var show: Show
|
|
var body: some View {
|
|
NavigationView(){
|
|
List(show.getSeasons(), id: \.self){ season in
|
|
NavigationLink(destination: SeasonView(season: season)){
|
|
Text(season.seasonName)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//not used at the moment, we have an integrated view of seasons in the episode list
|
|
struct SeasonView: View {
|
|
var season: Season
|
|
var body: some View {
|
|
NavigationView(){
|
|
List(season.getEpisodes(), id:\.self){ episode in
|
|
NavigationLink(destination: VideoView(episode: episode)){
|
|
HStack{
|
|
AsyncImage(url: episode.imageURL,placeholder: {
|
|
//Image(name: "loading")
|
|
Text("Loading...")
|
|
},image:{Image(uiImage:$0).resizable()
|
|
}).aspectRatio(contentMode: .fit).frame(width: 480, height:300)
|
|
Text(episode.name)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct VideoView: View {
|
|
var episode: Episode
|
|
@State var loginaction: Bool = false
|
|
|
|
|
|
var body: some View {
|
|
if episode.authenticated() || loginaction {
|
|
let player = AVPlayer(url: episode.getVideo().hlsUrl);
|
|
VideoPlayer(player: player).fixedSize().onAppear(){
|
|
player.play()
|
|
}
|
|
}else{
|
|
LoginView(vrtNu: episode.season.show.vrtNu, loginaction: $loginaction)
|
|
}
|
|
};
|
|
}
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
//ShowView(show: VRTNu().getShows()[0])
|
|
ContentView()
|
|
}
|
|
}
|
|
|