2021-07-12 02:22:49 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AppTabNavigation: View {
|
2021-10-23 04:34:03 +05:30
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
2021-12-05 01:05:41 +05:30
|
|
|
@EnvironmentObject<CommentsModel> private var comments
|
|
|
|
@EnvironmentObject<InstancesModel> private var instances
|
2021-09-25 13:48:22 +05:30
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
2021-10-23 04:34:03 +05:30
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
2021-12-05 01:05:41 +05:30
|
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
2021-09-25 17:47:58 +05:30
|
|
|
@EnvironmentObject<RecentsModel> private var recents
|
2021-10-23 04:34:03 +05:30
|
|
|
@EnvironmentObject<SearchModel> private var search
|
2021-12-05 01:05:41 +05:30
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
|
|
|
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
|
2021-09-19 16:36:54 +05:30
|
|
|
|
2021-12-01 16:52:19 +05:30
|
|
|
@Default(.visibleSections) private var visibleSections
|
2021-11-08 02:21:22 +05:30
|
|
|
|
2022-01-06 22:25:56 +05:30
|
|
|
let persistenceController = PersistenceController.shared
|
|
|
|
|
2021-07-12 02:22:49 +05:30
|
|
|
var body: some View {
|
2021-09-29 04:31:49 +05:30
|
|
|
TabView(selection: navigation.tabSelectionBinding) {
|
2021-12-01 16:52:19 +05:30
|
|
|
if visibleSections.contains(.favorites) {
|
|
|
|
favoritesNavigationView
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
|
|
|
|
2021-11-08 02:21:22 +05:30
|
|
|
if subscriptionsVisible {
|
2021-12-01 16:52:19 +05:30
|
|
|
subscriptionsNavigationView
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2021-09-19 02:06:42 +05:30
|
|
|
|
2021-12-03 02:05:42 +05:30
|
|
|
if visibleSections.contains(.popular), accounts.app.supportsPopular, visibleSections.count < 5 {
|
2021-12-01 16:52:19 +05:30
|
|
|
popularNavigationView
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
|
|
|
|
2021-12-01 16:52:19 +05:30
|
|
|
if visibleSections.contains(.trending) {
|
|
|
|
trendingNavigationView
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
|
|
|
|
2022-01-25 02:52:47 +05:30
|
|
|
if playlistsVisible {
|
2021-12-01 16:52:19 +05:30
|
|
|
playlistsNavigationView
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2021-12-01 16:52:19 +05:30
|
|
|
|
|
|
|
searchNavigationView
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2021-12-01 04:28:46 +05:30
|
|
|
.id(accounts.current?.id ?? "")
|
2021-09-19 18:12:47 +05:30
|
|
|
.environment(\.navigationStyle, .tab)
|
2021-12-01 04:28:46 +05:30
|
|
|
.background(
|
2022-01-06 22:25:56 +05:30
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingChannel) {
|
2021-12-01 04:28:46 +05:30
|
|
|
if let channel = recents.presentedChannel {
|
|
|
|
NavigationView {
|
|
|
|
ChannelVideosView(channel: channel)
|
2022-01-06 22:25:56 +05:30
|
|
|
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
2021-12-01 04:28:46 +05:30
|
|
|
.environment(\.inChannelView, true)
|
|
|
|
.environment(\.inNavigationView, true)
|
2021-12-18 01:28:24 +05:30
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(navigation)
|
|
|
|
.environmentObject(player)
|
|
|
|
.environmentObject(subscriptions)
|
|
|
|
.environmentObject(thumbnailsModel)
|
|
|
|
|
2021-12-01 04:28:46 +05:30
|
|
|
.background(playerNavigationLink)
|
|
|
|
}
|
2021-10-23 04:34:03 +05:30
|
|
|
}
|
|
|
|
}
|
2021-12-01 04:28:46 +05:30
|
|
|
)
|
|
|
|
.background(
|
2022-01-06 22:25:56 +05:30
|
|
|
EmptyView().sheet(isPresented: $navigation.presentingPlaylist) {
|
2021-12-01 04:28:46 +05:30
|
|
|
if let playlist = recents.presentedPlaylist {
|
|
|
|
NavigationView {
|
|
|
|
ChannelPlaylistView(playlist: playlist)
|
2022-01-06 22:25:56 +05:30
|
|
|
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
2021-12-01 04:28:46 +05:30
|
|
|
.environment(\.inNavigationView, true)
|
2021-12-18 01:28:24 +05:30
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(navigation)
|
|
|
|
.environmentObject(player)
|
2021-12-06 23:43:37 +05:30
|
|
|
.environmentObject(subscriptions)
|
2021-12-18 01:28:24 +05:30
|
|
|
.environmentObject(thumbnailsModel)
|
|
|
|
|
2021-12-01 04:28:46 +05:30
|
|
|
.background(playerNavigationLink)
|
|
|
|
}
|
2021-09-01 02:47:50 +05:30
|
|
|
}
|
|
|
|
}
|
2021-12-01 04:28:46 +05:30
|
|
|
)
|
2021-12-05 01:05:41 +05:30
|
|
|
.background(
|
|
|
|
EmptyView().fullScreenCover(isPresented: $player.presentingPlayer) {
|
|
|
|
videoPlayer
|
2022-01-06 22:25:56 +05:30
|
|
|
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
2021-12-18 01:28:24 +05:30
|
|
|
.environment(\.navigationStyle, .tab)
|
2021-12-05 01:05:41 +05:30
|
|
|
}
|
|
|
|
)
|
2021-09-01 02:47:50 +05:30
|
|
|
}
|
2021-09-25 13:48:22 +05:30
|
|
|
|
2021-12-01 16:52:19 +05:30
|
|
|
private var favoritesNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(FavoritesView())
|
|
|
|
.toolbar { toolbarContent }
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Favorites", systemImage: "heart")
|
|
|
|
.accessibility(label: Text("Favorites"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.favorites)
|
|
|
|
}
|
|
|
|
|
|
|
|
private var subscriptionsNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(SubscriptionsView())
|
|
|
|
.toolbar { toolbarContent }
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Subscriptions", systemImage: "star.circle.fill")
|
|
|
|
.accessibility(label: Text("Subscriptions"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.subscriptions)
|
|
|
|
}
|
|
|
|
|
2021-11-08 02:21:22 +05:30
|
|
|
private var subscriptionsVisible: Bool {
|
2021-12-01 16:52:19 +05:30
|
|
|
visibleSections.contains(.subscriptions) &&
|
|
|
|
accounts.app.supportsSubscriptions && !(accounts.current?.anonymous ?? true)
|
2021-11-08 02:21:22 +05:30
|
|
|
}
|
|
|
|
|
2022-01-25 02:52:47 +05:30
|
|
|
private var playlistsVisible: Bool {
|
|
|
|
visibleSections.contains(.playlists) &&
|
|
|
|
accounts.app.supportsUserPlaylists && !(accounts.current?.anonymous ?? true)
|
|
|
|
}
|
|
|
|
|
2021-11-08 02:21:22 +05:30
|
|
|
private var popularNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(PopularView())
|
|
|
|
.toolbar { toolbarContent }
|
|
|
|
}
|
|
|
|
.tabItem {
|
2021-11-28 20:07:55 +05:30
|
|
|
Label("Popular", systemImage: "arrow.up.right.circle")
|
2021-11-08 02:21:22 +05:30
|
|
|
.accessibility(label: Text("Popular"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.popular)
|
|
|
|
}
|
|
|
|
|
|
|
|
private var trendingNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(TrendingView())
|
|
|
|
.toolbar { toolbarContent }
|
|
|
|
}
|
|
|
|
.tabItem {
|
2021-11-28 20:07:55 +05:30
|
|
|
Label("Trending", systemImage: "chart.bar")
|
2021-11-08 02:21:22 +05:30
|
|
|
.accessibility(label: Text("Trending"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.trending)
|
|
|
|
}
|
|
|
|
|
2021-12-01 16:52:19 +05:30
|
|
|
private var playlistsNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(PlaylistsView())
|
|
|
|
.toolbar { toolbarContent }
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Playlists", systemImage: "list.and.film")
|
|
|
|
.accessibility(label: Text("Playlists"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.playlists)
|
|
|
|
}
|
|
|
|
|
|
|
|
private var searchNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(SearchView())
|
|
|
|
.toolbar { toolbarContent }
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Search", systemImage: "magnifyingglass")
|
|
|
|
.accessibility(label: Text("Search"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.search)
|
|
|
|
}
|
|
|
|
|
2021-10-23 04:34:03 +05:30
|
|
|
private var playerNavigationLink: some View {
|
|
|
|
NavigationLink(isActive: $player.playerNavigationLinkActive, destination: {
|
2021-12-18 01:28:24 +05:30
|
|
|
videoPlayer
|
2021-10-23 04:34:03 +05:30
|
|
|
.environment(\.inNavigationView, true)
|
|
|
|
}) {
|
|
|
|
EmptyView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-05 01:05:41 +05:30
|
|
|
private var videoPlayer: some View {
|
|
|
|
VideoPlayerView()
|
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(comments)
|
|
|
|
.environmentObject(instances)
|
|
|
|
.environmentObject(navigation)
|
|
|
|
.environmentObject(player)
|
|
|
|
.environmentObject(playlists)
|
|
|
|
.environmentObject(recents)
|
|
|
|
.environmentObject(subscriptions)
|
|
|
|
.environmentObject(thumbnailsModel)
|
|
|
|
}
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
var toolbarContent: some ToolbarContent {
|
|
|
|
#if os(iOS)
|
|
|
|
Group {
|
|
|
|
ToolbarItemGroup(placement: .navigationBarLeading) {
|
|
|
|
Button(action: { navigation.presentingSettings = true }) {
|
|
|
|
Image(systemName: "gearshape.2")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
|
|
|
AccountsMenuView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|