1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Navigation/ContentView.swift

182 lines
6.1 KiB
Swift
Raw Normal View History

import AVFAudio
2021-09-25 13:48:22 +05:30
import Defaults
2022-02-17 02:40:57 +05:30
import MediaPlayer
import SDWebImage
import SDWebImagePINPlugin
import SDWebImageWebPCoder
2021-10-17 04:18:58 +05:30
import Siesta
2021-06-10 02:21:23 +05:30
import SwiftUI
struct ContentView: View {
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<CommentsModel> private var comments
@EnvironmentObject<InstancesModel> private var instances
@EnvironmentObject<NavigationModel> private var navigation
2022-09-01 23:31:01 +05:30
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<PlaylistsModel> private var playlists
@EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SearchModel> private var search
@EnvironmentObject<SettingsModel> private var settings
@EnvironmentObject<SubscriptionsModel> private var subscriptions
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
2021-09-25 13:48:22 +05:30
2021-11-09 04:44:28 +05:30
@EnvironmentObject<MenuModel> private var menu
2021-07-12 02:22:49 +05:30
#if os(iOS)
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
#endif
2021-06-12 02:41:59 +05:30
2022-08-29 19:01:36 +05:30
@State private var playerInitialized = false
2022-09-01 23:31:01 +05:30
var playerControls: PlayerControlsModel { .shared }
2022-09-01 22:30:56 +05:30
2022-05-29 23:56:56 +05:30
let persistenceController = PersistenceController.shared
2021-06-10 02:21:23 +05:30
var body: some View {
2021-12-01 04:28:11 +05:30
Group {
2021-07-12 02:22:49 +05:30
#if os(iOS)
if horizontalSizeClass == .compact {
AppTabNavigation()
} else {
AppSidebarNavigation()
2021-06-12 02:41:59 +05:30
}
2021-07-12 02:22:49 +05:30
#elseif os(macOS)
AppSidebarNavigation()
#elseif os(tvOS)
TVNavigationView()
.environmentObject(settings)
2021-07-12 02:22:49 +05:30
#endif
2021-07-30 04:04:13 +05:30
}
.onChange(of: accounts.current) { _ in
subscriptions.load(force: true)
playlists.load(force: true)
}
.onChange(of: accounts.signedIn) { _ in
subscriptions.load(force: true)
playlists.load(force: true)
}
2021-10-17 04:18:58 +05:30
.environmentObject(accounts)
2021-12-05 01:05:41 +05:30
.environmentObject(comments)
.environmentObject(instances)
2021-09-25 13:48:22 +05:30
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(playlists)
2021-09-25 13:48:22 +05:30
.environmentObject(recents)
.environmentObject(search)
.environmentObject(subscriptions)
2021-10-25 03:56:25 +05:30
.environmentObject(thumbnailsModel)
2022-05-29 17:59:43 +05:30
#if os(iOS)
.overlay(videoPlayer)
.sheet(isPresented: $navigation.presentingShareSheet) {
if let shareURL = navigation.shareURL {
ShareSheet(activityItems: [shareURL])
}
}
2021-08-02 04:31:24 +05:30
#endif
// iOS 14 has problem with multiple sheets in one view
// but it's ok when it's in background
.background(
EmptyView().sheet(isPresented: $navigation.presentingWelcomeScreen) {
WelcomeScreen()
.environmentObject(accounts)
.environmentObject(navigation)
}
)
#if !os(tvOS)
2022-06-25 04:18:57 +05:30
.onOpenURL {
OpenURLHandler(
accounts: accounts,
navigation: navigation,
recents: recents,
player: player,
2022-06-30 13:35:32 +05:30
search: search,
navigationStyle: navigationStyle
2022-06-25 04:18:57 +05:30
).handle($0)
}
.background(
EmptyView().sheet(isPresented: $navigation.presentingAddToPlaylist) {
AddToPlaylistView(video: navigation.videoToAddToPlaylist)
.environmentObject(playlists)
}
)
.background(
EmptyView().sheet(isPresented: $navigation.presentingPlaylistForm) {
PlaylistFormView(playlist: $navigation.editedPlaylist)
.environmentObject(accounts)
.environmentObject(playlists)
}
)
.background(
EmptyView().sheet(isPresented: $navigation.presentingSettings) {
SettingsView()
.environmentObject(accounts)
.environmentObject(instances)
.environmentObject(settings)
.environmentObject(navigation)
.environmentObject(player)
}
)
#endif
2022-08-29 19:01:36 +05:30
.background(playerViewInitialize)
2022-06-25 04:18:57 +05:30
.alert(isPresented: $navigation.presentingAlert) { navigation.alert }
2022-02-17 02:40:57 +05:30
}
2022-06-30 13:35:32 +05:30
var navigationStyle: NavigationStyle {
#if os(iOS)
return horizontalSizeClass == .compact ? .tab : .sidebar
#elseif os(tvOS)
return .tab
#else
return .sidebar
#endif
}
2022-07-09 05:51:04 +05:30
@ViewBuilder var videoPlayer: some View {
2022-08-08 23:32:46 +05:30
if player.presentingPlayer {
2022-08-19 04:10:46 +05:30
playerView
2022-08-25 22:39:55 +05:30
.transition(.asymmetric(insertion: .identity, removal: .move(edge: .bottom)))
.zIndex(3)
2022-08-19 04:10:46 +05:30
} else if player.activeBackend == .appleAVPlayer {
#if os(iOS)
playerView.offset(y: UIScreen.main.bounds.height)
#endif
2022-08-08 23:32:46 +05:30
}
}
2022-08-19 04:10:46 +05:30
var playerView: some View {
VideoPlayerView()
.environmentObject(accounts)
.environmentObject(comments)
.environmentObject(instances)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(playerControls)
.environmentObject(playlists)
.environmentObject(recents)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
.environment(\.navigationStyle, navigationStyle)
}
2022-08-29 19:01:36 +05:30
@ViewBuilder var playerViewInitialize: some View {
if !playerInitialized {
VideoPlayerView()
.scaleEffect(0.00001)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
playerInitialized = true
}
}
}
}
2021-06-10 02:21:23 +05:30
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
2021-09-29 17:15:00 +05:30
.injectFixtureEnvironmentObjects()
2021-06-10 02:21:23 +05:30
}
}