2021-11-01 21:56:18 +00:00
|
|
|
import Defaults
|
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
import UniformTypeIdentifiers
|
|
|
|
|
2022-11-09 13:34:04 +00:00
|
|
|
struct HomeView: View {
|
2021-11-01 21:56:18 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
|
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
|
|
|
|
|
|
|
@State private var dragging: FavoriteItem?
|
|
|
|
@State private var presentingEditFavorites = false
|
|
|
|
|
2021-11-07 16:52:42 +00:00
|
|
|
@State private var favoritesChanged = false
|
|
|
|
|
|
|
|
var favoritesObserver: Any?
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
@Default(.favorites) private var favorites
|
|
|
|
#endif
|
2022-11-10 17:11:28 +00:00
|
|
|
@Default(.homeHistoryItems) private var homeHistoryItems
|
2021-11-07 16:52:42 +00:00
|
|
|
|
2022-11-09 13:34:04 +00:00
|
|
|
private var navigation: NavigationModel { .shared }
|
|
|
|
|
2021-11-01 21:56:18 +00:00
|
|
|
var body: some View {
|
2022-02-16 20:23:11 +00:00
|
|
|
BrowserPlayerControls {
|
2021-11-01 21:56:18 +00:00
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
|
|
if !accounts.current.isNil {
|
|
|
|
#if os(tvOS)
|
2021-11-07 16:52:42 +00:00
|
|
|
ForEach(Defaults[.favorites]) { item in
|
|
|
|
FavoriteItemView(item: item, dragging: $dragging)
|
|
|
|
}
|
|
|
|
#else
|
2022-01-05 16:25:57 +00:00
|
|
|
#if os(iOS)
|
|
|
|
let first = favorites.first
|
|
|
|
#endif
|
2021-11-07 16:52:42 +00:00
|
|
|
ForEach(favorites) { item in
|
|
|
|
FavoriteItemView(item: item, dragging: $dragging)
|
2021-12-02 19:19:10 +00:00
|
|
|
#if os(macOS)
|
|
|
|
.workaroundForVerticalScrollingBug()
|
|
|
|
#endif
|
2022-01-05 16:25:57 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.padding(.top, item == first && RefreshControl.navigationBarTitleDisplayMode == .inline ? 10 : 0)
|
|
|
|
#endif
|
2021-11-01 21:56:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2022-11-09 13:34:04 +00:00
|
|
|
|
|
|
|
VStack {
|
|
|
|
Text("History")
|
|
|
|
|
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 40)
|
|
|
|
#else
|
|
|
|
.padding(.horizontal, 15)
|
|
|
|
#endif
|
|
|
|
.font(.title3.bold())
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
2022-11-10 17:11:28 +00:00
|
|
|
HistoryView(limit: homeHistoryItems)
|
2022-11-09 13:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if os(tvOS)
|
|
|
|
HStack {
|
|
|
|
Button {
|
|
|
|
navigation.presentingOpenVideos = true
|
|
|
|
} label: {
|
|
|
|
Label("Open Videos...", systemImage: "folder")
|
|
|
|
.padding(.horizontal, 20)
|
|
|
|
.padding(.vertical, 10)
|
|
|
|
}
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
Color.clear.padding(.bottom, 60)
|
|
|
|
#endif
|
2021-11-01 21:56:18 +00:00
|
|
|
}
|
2021-11-07 16:52:42 +00:00
|
|
|
.onAppear {
|
|
|
|
Defaults.observe(.favorites) { _ in
|
|
|
|
favoritesChanged.toggle()
|
|
|
|
}
|
|
|
|
.tieToLifetime(of: accounts)
|
|
|
|
}
|
2022-08-28 18:00:43 +00:00
|
|
|
|
2021-11-07 16:52:42 +00:00
|
|
|
.redrawOn(change: favoritesChanged)
|
|
|
|
|
2021-11-01 21:56:18 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
.edgesIgnoringSafeArea(.horizontal)
|
|
|
|
#else
|
|
|
|
.onDrop(of: [UTType.text], delegate: DropFavoriteOutside(current: $dragging))
|
2022-11-09 13:34:04 +00:00
|
|
|
.navigationTitle("Home")
|
2021-11-01 21:56:18 +00:00
|
|
|
#endif
|
|
|
|
#if os(macOS)
|
2021-12-19 23:36:12 +00:00
|
|
|
.background(Color.secondaryBackground)
|
2021-11-08 16:29:35 +00:00
|
|
|
.frame(minWidth: 360)
|
2021-11-01 21:56:18 +00:00
|
|
|
#endif
|
2022-01-05 16:25:57 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
|
|
|
|
#endif
|
2022-08-28 18:00:43 +00:00
|
|
|
#if !os(macOS)
|
|
|
|
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
|
|
|
favoritesChanged.toggle()
|
|
|
|
}
|
|
|
|
#endif
|
2021-11-01 21:56:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Favorites_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-06-18 12:39:49 +00:00
|
|
|
TabView {
|
2022-11-09 13:34:04 +00:00
|
|
|
HomeView()
|
|
|
|
// .overlay(VideoPlayerView().injectFixtureEnvironmentObjects())
|
2022-06-18 12:39:49 +00:00
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
.tabItem {
|
2022-11-09 13:34:04 +00:00
|
|
|
Label("Home", systemImage: "house")
|
2022-06-18 12:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-01 21:56:18 +00:00
|
|
|
}
|
|
|
|
}
|