2021-07-12 02:22:49 +05:30
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
final class NavigationModel: ObservableObject {
|
2021-08-30 03:06:18 +05:30
|
|
|
enum TabSelection: Hashable {
|
2021-11-02 03:26:18 +05:30
|
|
|
case favorites
|
2021-10-06 01:50:09 +05:30
|
|
|
case subscriptions
|
|
|
|
case popular
|
|
|
|
case trending
|
|
|
|
case playlists
|
|
|
|
case channel(String)
|
|
|
|
case playlist(String)
|
|
|
|
case recentlyOpened(String)
|
|
|
|
case nowPlaying
|
|
|
|
case search
|
2021-10-25 03:06:24 +05:30
|
|
|
|
|
|
|
var playlistID: Playlist.ID? {
|
|
|
|
if case let .playlist(id) = self {
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-08-30 03:06:18 +05:30
|
|
|
}
|
|
|
|
|
2021-12-01 16:52:19 +05:30
|
|
|
@Published var tabSelection: TabSelection!
|
2021-07-12 02:22:49 +05:30
|
|
|
|
2021-09-28 23:36:05 +05:30
|
|
|
@Published var presentingAddToPlaylist = false
|
|
|
|
@Published var videoToAddToPlaylist: Video!
|
|
|
|
|
2021-08-30 03:06:18 +05:30
|
|
|
@Published var presentingPlaylistForm = false
|
|
|
|
@Published var editedPlaylist: Playlist!
|
|
|
|
|
|
|
|
@Published var presentingUnsubscribeAlert = false
|
|
|
|
@Published var channelToUnsubscribe: Channel!
|
|
|
|
|
2021-10-23 04:34:03 +05:30
|
|
|
@Published var presentingChannel = false
|
|
|
|
@Published var presentingPlaylist = false
|
2021-09-01 02:47:50 +05:30
|
|
|
@Published var sidebarSectionChanged = false
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
@Published var presentingSettings = false
|
2021-10-18 04:36:00 +05:30
|
|
|
@Published var presentingWelcomeScreen = false
|
2021-09-25 13:48:22 +05:30
|
|
|
|
2021-12-17 22:04:55 +05:30
|
|
|
static func openChannel(
|
|
|
|
_ channel: Channel,
|
|
|
|
player: PlayerModel,
|
|
|
|
recents: RecentsModel,
|
|
|
|
navigation: NavigationModel,
|
2022-01-06 22:25:56 +05:30
|
|
|
navigationStyle: NavigationStyle,
|
2022-01-09 20:17:00 +05:30
|
|
|
delay: Bool = true
|
2021-12-17 22:04:55 +05:30
|
|
|
) {
|
|
|
|
let recent = RecentItem(from: channel)
|
2021-12-19 22:47:04 +05:30
|
|
|
#if os(macOS)
|
2022-01-06 21:05:45 +05:30
|
|
|
Windows.main.open()
|
2021-12-19 22:47:04 +05:30
|
|
|
#else
|
|
|
|
player.hide()
|
|
|
|
#endif
|
2021-12-17 22:04:55 +05:30
|
|
|
|
|
|
|
let openRecent = {
|
|
|
|
recents.add(recent)
|
|
|
|
navigation.presentingChannel = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if navigationStyle == .tab {
|
2022-01-06 22:25:56 +05:30
|
|
|
if delay {
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
|
openRecent()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
openRecent()
|
|
|
|
}
|
|
|
|
} else if navigationStyle == .sidebar {
|
|
|
|
openRecent()
|
|
|
|
navigation.sidebarSectionChanged.toggle()
|
|
|
|
navigation.tabSelection = .recentlyOpened(recent.tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static func openChannelPlaylist(
|
|
|
|
_ playlist: ChannelPlaylist,
|
|
|
|
player: PlayerModel,
|
|
|
|
recents: RecentsModel,
|
|
|
|
navigation: NavigationModel,
|
|
|
|
navigationStyle: NavigationStyle,
|
|
|
|
delay: Bool = false
|
|
|
|
) {
|
|
|
|
let recent = RecentItem(from: playlist)
|
|
|
|
#if os(macOS)
|
|
|
|
Windows.main.open()
|
|
|
|
#else
|
|
|
|
player.hide()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
let openRecent = {
|
|
|
|
recents.add(recent)
|
|
|
|
navigation.presentingPlaylist = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if navigationStyle == .tab {
|
|
|
|
if delay {
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
|
openRecent()
|
|
|
|
}
|
|
|
|
} else {
|
2021-12-17 22:04:55 +05:30
|
|
|
openRecent()
|
|
|
|
}
|
|
|
|
} else if navigationStyle == .sidebar {
|
|
|
|
openRecent()
|
|
|
|
navigation.sidebarSectionChanged.toggle()
|
|
|
|
navigation.tabSelection = .recentlyOpened(recent.tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 04:31:49 +05:30
|
|
|
var tabSelectionBinding: Binding<TabSelection> {
|
|
|
|
Binding<TabSelection>(
|
2021-07-12 02:22:49 +05:30
|
|
|
get: {
|
2021-12-20 05:06:12 +05:30
|
|
|
self.tabSelection ?? .search
|
2021-07-12 02:22:49 +05:30
|
|
|
},
|
2021-09-01 02:47:50 +05:30
|
|
|
set: { newValue in
|
2021-09-29 04:31:49 +05:30
|
|
|
self.tabSelection = newValue
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2021-08-30 03:06:18 +05:30
|
|
|
|
2021-09-28 23:36:05 +05:30
|
|
|
func presentAddToPlaylist(_ video: Video) {
|
|
|
|
videoToAddToPlaylist = video
|
|
|
|
presentingAddToPlaylist = true
|
|
|
|
}
|
|
|
|
|
2021-08-30 03:06:18 +05:30
|
|
|
func presentEditPlaylistForm(_ playlist: Playlist?) {
|
|
|
|
editedPlaylist = playlist
|
|
|
|
presentingPlaylistForm = editedPlaylist != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func presentNewPlaylistForm() {
|
|
|
|
editedPlaylist = nil
|
|
|
|
presentingPlaylistForm = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func presentUnsubscribeAlert(_ channel: Channel?) {
|
|
|
|
channelToUnsubscribe = channel
|
|
|
|
presentingUnsubscribeAlert = channelToUnsubscribe != nil
|
|
|
|
}
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2021-08-30 03:06:18 +05:30
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
typealias TabSelection = NavigationModel.TabSelection
|