2021-07-11 20:52:49 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AppTabNavigation: View {
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var accounts = AccountsModel.shared
|
|
|
|
@ObservedObject private var navigation = NavigationModel.shared
|
|
|
|
private var player = PlayerModel.shared
|
2022-12-12 23:39:50 +00:00
|
|
|
@ObservedObject private var feed = FeedModel.shared
|
2022-12-16 21:26:14 +00:00
|
|
|
@ObservedObject private var feedCount = UnwatchedFeedCountModel.shared
|
2023-05-29 13:54:11 +00:00
|
|
|
private var recents = RecentsModel.shared
|
2021-09-19 11:06:54 +00:00
|
|
|
|
2022-11-11 20:28:40 +00:00
|
|
|
@Default(.showHome) private var showHome
|
2022-11-12 23:01:04 +00:00
|
|
|
@Default(.showDocuments) private var showDocuments
|
2022-11-11 20:28:40 +00:00
|
|
|
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
|
2021-12-01 11:22:19 +00:00
|
|
|
@Default(.visibleSections) private var visibleSections
|
2023-02-28 20:17:12 +00:00
|
|
|
@Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges
|
2021-11-07 20:51:22 +00:00
|
|
|
|
2022-01-06 16:55:56 +00:00
|
|
|
let persistenceController = PersistenceController.shared
|
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
var body: some View {
|
2021-09-28 23:01:49 +00:00
|
|
|
TabView(selection: navigation.tabSelectionBinding) {
|
2022-12-10 21:37:14 +00:00
|
|
|
Group {
|
2022-11-11 20:28:40 +00:00
|
|
|
if showHome {
|
|
|
|
homeNavigationView
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
|
2022-11-12 23:01:04 +00:00
|
|
|
if showDocuments {
|
|
|
|
documentsNavigationView
|
|
|
|
}
|
|
|
|
|
2022-11-11 20:28:40 +00:00
|
|
|
if !accounts.isEmpty {
|
|
|
|
if subscriptionsVisible {
|
|
|
|
subscriptionsNavigationView
|
|
|
|
}
|
2021-09-18 20:36:42 +00:00
|
|
|
|
2022-11-11 20:28:40 +00:00
|
|
|
if visibleSections.contains(.popular), accounts.app.supportsPopular, visibleSections.count < 5 {
|
|
|
|
popularNavigationView
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
|
2022-11-11 20:28:40 +00:00
|
|
|
if visibleSections.contains(.trending) {
|
|
|
|
trendingNavigationView
|
|
|
|
}
|
|
|
|
|
|
|
|
if playlistsVisible {
|
|
|
|
playlistsNavigationView
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
|
2022-11-11 20:28:40 +00:00
|
|
|
searchNavigationView
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
2022-12-17 18:35:07 +00:00
|
|
|
.modifier(PlayerOverlayModifier())
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
2022-12-12 23:39:50 +00:00
|
|
|
.onAppear {
|
|
|
|
feed.calculateUnwatchedFeed()
|
|
|
|
}
|
|
|
|
.onChange(of: accounts.current) { _ in
|
|
|
|
feed.calculateUnwatchedFeed()
|
|
|
|
}
|
2021-11-30 22:58:46 +00:00
|
|
|
.id(accounts.current?.id ?? "")
|
2022-05-29 19:09:57 +00:00
|
|
|
.overlay(playlistView)
|
2022-05-29 20:12:59 +00:00
|
|
|
.overlay(channelView)
|
2022-05-29 19:09:57 +00:00
|
|
|
.environment(\.navigationStyle, .tab)
|
2021-08-31 21:17:50 +00:00
|
|
|
}
|
2021-09-25 08:18:22 +00:00
|
|
|
|
2022-11-09 13:34:04 +00:00
|
|
|
private var homeNavigationView: some View {
|
2021-12-01 11:22:19 +00:00
|
|
|
NavigationView {
|
2022-11-09 13:34:04 +00:00
|
|
|
LazyView(HomeView())
|
2021-12-01 11:22:19 +00:00
|
|
|
.toolbar { toolbarContent }
|
|
|
|
}
|
|
|
|
.tabItem {
|
2022-11-09 13:34:04 +00:00
|
|
|
Label("Home", systemImage: "house.fill")
|
|
|
|
.accessibility(label: Text("Home"))
|
2021-12-01 11:22:19 +00:00
|
|
|
}
|
2022-11-09 13:34:04 +00:00
|
|
|
.tag(TabSelection.home)
|
2021-12-01 11:22:19 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 23:01:04 +00:00
|
|
|
private var documentsNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(DocumentsView())
|
|
|
|
.toolbar { toolbarContent }
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Documents", systemImage: "folder")
|
|
|
|
.accessibility(label: Text("Documents"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.documents)
|
|
|
|
}
|
|
|
|
|
2021-12-01 11:22:19 +00:00
|
|
|
private var subscriptionsNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(SubscriptionsView())
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Subscriptions", systemImage: "star.circle.fill")
|
|
|
|
.accessibility(label: Text("Subscriptions"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.subscriptions)
|
2022-12-12 23:39:50 +00:00
|
|
|
.backport
|
2023-02-28 20:17:12 +00:00
|
|
|
.badge(showUnwatchedFeedBadges ? feedCount.unwatchedText : nil)
|
2021-12-01 11:22:19 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 20:51:22 +00:00
|
|
|
private var subscriptionsVisible: Bool {
|
2021-12-01 11:22:19 +00:00
|
|
|
visibleSections.contains(.subscriptions) &&
|
|
|
|
accounts.app.supportsSubscriptions && !(accounts.current?.anonymous ?? true)
|
2021-11-07 20:51:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 21:22:47 +00:00
|
|
|
private var playlistsVisible: Bool {
|
|
|
|
visibleSections.contains(.playlists) &&
|
|
|
|
accounts.app.supportsUserPlaylists && !(accounts.current?.anonymous ?? true)
|
|
|
|
}
|
|
|
|
|
2021-11-07 20:51:22 +00:00
|
|
|
private var popularNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(PopularView())
|
|
|
|
.toolbar { toolbarContent }
|
|
|
|
}
|
|
|
|
.tabItem {
|
2022-02-16 20:23:11 +00:00
|
|
|
Label("Popular", systemImage: "arrow.up.right.circle.fill")
|
2021-11-07 20:51:22 +00:00
|
|
|
.accessibility(label: Text("Popular"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.popular)
|
|
|
|
}
|
|
|
|
|
|
|
|
private var trendingNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(TrendingView())
|
|
|
|
}
|
|
|
|
.tabItem {
|
2022-02-16 20:23:11 +00:00
|
|
|
Label("Trending", systemImage: "chart.bar.fill")
|
2021-11-07 20:51:22 +00:00
|
|
|
.accessibility(label: Text("Trending"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.trending)
|
|
|
|
}
|
|
|
|
|
2021-12-01 11:22:19 +00:00
|
|
|
private var playlistsNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(PlaylistsView())
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Playlists", systemImage: "list.and.film")
|
|
|
|
.accessibility(label: Text("Playlists"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.playlists)
|
|
|
|
}
|
|
|
|
|
|
|
|
private var searchNavigationView: some View {
|
|
|
|
NavigationView {
|
|
|
|
LazyView(SearchView())
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Search", systemImage: "magnifyingglass")
|
|
|
|
.accessibility(label: Text("Search"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.search)
|
|
|
|
}
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
var toolbarContent: some ToolbarContent {
|
|
|
|
#if os(iOS)
|
|
|
|
Group {
|
|
|
|
ToolbarItemGroup(placement: .navigationBarLeading) {
|
|
|
|
Button(action: { navigation.presentingSettings = true }) {
|
|
|
|
Image(systemName: "gearshape.2")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
2022-11-11 20:28:40 +00:00
|
|
|
if showOpenActionsToolbarItem {
|
|
|
|
Button(action: { navigation.presentingOpenVideos = true }) {
|
|
|
|
Label("Open Videos", systemImage: "play.circle.fill")
|
|
|
|
}
|
2022-11-10 17:11:28 +00:00
|
|
|
}
|
2022-12-12 00:18:29 +00:00
|
|
|
AccountViewButton()
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2022-05-29 18:26:56 +00:00
|
|
|
|
2022-07-09 00:21:04 +00:00
|
|
|
@ViewBuilder private var channelView: some View {
|
2023-05-29 14:31:01 +00:00
|
|
|
if navigation.presentingChannel, let channel = recents.presentedChannel {
|
2022-12-11 11:38:57 +00:00
|
|
|
NavigationView {
|
2023-05-29 14:31:01 +00:00
|
|
|
ChannelVideosView(channel: channel, showCloseButton: true)
|
2022-12-11 11:38:57 +00:00
|
|
|
}
|
|
|
|
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
|
|
|
.environment(\.inChannelView, true)
|
|
|
|
.environment(\.navigationStyle, .tab)
|
|
|
|
.id("channelVideos")
|
|
|
|
.zIndex(player.presentingPlayer ? -1 : 2)
|
|
|
|
.transition(.move(edge: .bottom))
|
2022-07-09 00:21:04 +00:00
|
|
|
}
|
2022-05-29 18:26:56 +00:00
|
|
|
}
|
2022-05-29 19:09:57 +00:00
|
|
|
|
2022-07-09 00:21:04 +00:00
|
|
|
@ViewBuilder private var playlistView: some View {
|
2023-05-29 13:54:11 +00:00
|
|
|
if navigation.presentingPlaylist, let playlist = recents.presentedPlaylist {
|
2022-12-11 11:38:57 +00:00
|
|
|
NavigationView {
|
2023-05-29 13:54:11 +00:00
|
|
|
ChannelPlaylistView(playlist: playlist, showCloseButton: true)
|
2022-12-11 11:38:57 +00:00
|
|
|
}
|
|
|
|
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
|
|
|
.id("channelPlaylist")
|
|
|
|
.zIndex(player.presentingPlayer ? -1 : 1)
|
|
|
|
.transition(.move(edge: .bottom))
|
2022-07-09 00:21:04 +00:00
|
|
|
}
|
2022-05-29 19:09:57 +00:00
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
2022-12-10 21:37:14 +00:00
|
|
|
|
|
|
|
struct AppTabNavigation_Preview: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
AppTabNavigation()
|
|
|
|
}
|
|
|
|
}
|