mirror of
https://github.com/yattee/yattee.git
synced 2025-10-29 19:51:54 +00:00
Simple view display switching
This commit is contained in:
@@ -8,15 +8,13 @@ struct PlayerViewController: UIViewControllerRepresentable {
|
||||
|
||||
@ObservedObject private var state: PlayerState
|
||||
|
||||
@ObservedObject private var profile = Profile()
|
||||
|
||||
var video: Video
|
||||
|
||||
init(video: Video) {
|
||||
self.video = video
|
||||
state = PlayerState(video)
|
||||
|
||||
loadStream(video.defaultStreamForProfile(profile), loadBest: profile.defaultStreamResolution == .hd720pFirstThenBest)
|
||||
loadStream(video.defaultStreamForProfile(state.profile), loadBest: state.profile.defaultStreamResolution == .hd720pFirstThenBest)
|
||||
}
|
||||
|
||||
fileprivate func loadStream(_ stream: Stream?, loadBest: Bool = false) {
|
||||
|
||||
@@ -64,8 +64,13 @@ struct PlaylistsView: View {
|
||||
|
||||
extension Array where Element: Equatable {
|
||||
func next(after element: Element) -> Element? {
|
||||
let idx = firstIndex(of: element)!
|
||||
let next = index(after: idx)
|
||||
let idx = firstIndex(of: element)
|
||||
|
||||
if idx == nil {
|
||||
return first
|
||||
}
|
||||
|
||||
let next = index(after: idx!)
|
||||
|
||||
return self[next == endIndex ? startIndex : next]
|
||||
}
|
||||
|
||||
@@ -7,11 +7,6 @@ struct PopularVideosView: View {
|
||||
|
||||
var body: some View {
|
||||
VideosView(tabSelection: $tabSelection, videos: videos)
|
||||
.task {
|
||||
Task {
|
||||
provider.load()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var videos: [Video] {
|
||||
|
||||
@@ -2,6 +2,7 @@ import SwiftUI
|
||||
|
||||
struct SearchView: View {
|
||||
@ObservedObject private var provider = SearchedVideosProvider()
|
||||
@EnvironmentObject private var profile: Profile
|
||||
@EnvironmentObject private var state: AppState
|
||||
|
||||
@Binding var tabSelection: TabSelection
|
||||
@@ -11,6 +12,7 @@ struct SearchView: View {
|
||||
var body: some View {
|
||||
VideosView(tabSelection: $tabSelection, videos: videos)
|
||||
.environmentObject(state)
|
||||
.environmentObject(profile)
|
||||
.searchable(text: $query)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SubscriptionsView: View {
|
||||
@ObservedObject private var provider = SubscriptionVideosProvider()
|
||||
@EnvironmentObject private var state: AppState
|
||||
|
||||
@Binding var tabSelection: TabSelection
|
||||
|
||||
@ObservedObject private var provider = SubscriptionVideosProvider()
|
||||
|
||||
var body: some View {
|
||||
VideosView(tabSelection: $tabSelection, videos: videos)
|
||||
.task {
|
||||
Task {
|
||||
provider.load()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var videos: [Video] {
|
||||
provider.videos
|
||||
if provider.videos.isEmpty {
|
||||
provider.load()
|
||||
}
|
||||
|
||||
return provider.videos
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
import SwiftUI
|
||||
|
||||
struct VideosView: View {
|
||||
@EnvironmentObject private var state: AppState
|
||||
@EnvironmentObject private var profile: Profile
|
||||
|
||||
@Binding var tabSelection: TabSelection
|
||||
var videos: [Video]
|
||||
|
||||
@State private var showingViewOptions = false
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if state.profile.listing == .list {
|
||||
Section {
|
||||
if self.profile.listing == .list {
|
||||
VideosListView(tabSelection: $tabSelection, videos: videos)
|
||||
} else {
|
||||
VideosCellsView(videos: videos, columns: state.profile.cellsColumns)
|
||||
VideosCellsView(videos: videos, columns: self.profile.cellsColumns)
|
||||
}
|
||||
}
|
||||
.fullScreenCover(isPresented: $showingViewOptions) { ViewOptionsView() }
|
||||
.onPlayPauseCommand { showingViewOptions.toggle() }
|
||||
}
|
||||
}
|
||||
|
||||
32
Apple TV/ViewOptionsView.swift
Normal file
32
Apple TV/ViewOptionsView.swift
Normal file
@@ -0,0 +1,32 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ViewOptionsView: View {
|
||||
@EnvironmentObject private var profile: Profile
|
||||
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
VisualEffectView(effect: UIBlurEffect(style: .dark))
|
||||
|
||||
VStack {
|
||||
Spacer()
|
||||
|
||||
ScrollView(.vertical) {
|
||||
Button(profile.listing == .list ? "Cells" : "List") {
|
||||
profile.listing = (profile.listing == .list ? .cells : .list)
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
|
||||
Button("Close") {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
.frame(width: 800)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user