Home Settings

This commit is contained in:
Arkadiusz Fal
2023-05-25 14:28:29 +02:00
parent 12afb31c03
commit 0061bd8c20
26 changed files with 911 additions and 396 deletions

View File

@@ -6,7 +6,7 @@ import UniformTypeIdentifiers
struct HomeView: View {
@ObservedObject private var accounts = AccountsModel.shared
@State private var presentingEditFavorites = false
@State private var presentingHomeSettings = false
@State private var favoritesChanged = false
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
@@ -20,9 +20,7 @@ struct HomeView: View {
#if !os(tvOS)
@Default(.favorites) private var favorites
#endif
#if os(iOS)
@Default(.homeRecentDocumentsItems) private var homeRecentDocumentsItems
@Default(.widgetsSettings) private var widgetsSettings
#endif
@Default(.homeHistoryItems) private var homeHistoryItems
@Default(.showFavoritesInHome) private var showFavoritesInHome
@@ -33,33 +31,45 @@ struct HomeView: View {
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
HStack {
#if os(tvOS)
Group {
if showOpenActionsInHome {
AccentButton(text: "Open Video", imageSystemName: "globe") {
NavigationModel.shared.presentingOpenVideos = true
VStack {
HStack {
#if os(tvOS)
Group {
if showOpenActionsInHome {
AccentButton(text: "Open Video", imageSystemName: "globe") {
NavigationModel.shared.presentingOpenVideos = true
}
}
AccentButton(text: "Locations", imageSystemName: "globe") {
NavigationModel.shared.presentingAccounts = true
}
AccentButton(text: "Settings", imageSystemName: "gear") {
NavigationModel.shared.presentingSettings = true
}
}
AccentButton(text: "Locations", imageSystemName: "globe") {
NavigationModel.shared.presentingAccounts = true
#else
if showOpenActionsInHome {
AccentButton(text: "Files", imageSystemName: "folder") {
NavigationModel.shared.presentingFileImporter = true
}
AccentButton(text: "Paste", imageSystemName: "doc.on.clipboard.fill") {
OpenVideosModel.shared.openURLsFromClipboard(playbackMode: .playNow)
}
AccentButton(imageSystemName: "ellipsis") {
NavigationModel.shared.presentingOpenVideos = true
}
.frame(maxWidth: 40)
}
AccentButton(text: "Settings", imageSystemName: "gear") {
NavigationModel.shared.presentingSettings = true
}
}
#else
if showOpenActionsInHome {
AccentButton(text: "Files", imageSystemName: "folder") {
NavigationModel.shared.presentingFileImporter = true
}
AccentButton(text: "Paste", imageSystemName: "doc.on.clipboard.fill") {
OpenVideosModel.shared.openURLsFromClipboard(playbackMode: .playNow)
}
AccentButton(imageSystemName: "ellipsis") {
NavigationModel.shared.presentingOpenVideos = true
}
.frame(maxWidth: 40)
#endif
}
#if os(tvOS)
HStack {
Spacer()
HideWatchedButtons()
HideShortsButtons()
HomeSettingsButton()
}
#endif
}
@@ -80,7 +90,7 @@ struct HomeView: View {
}
if !accounts.current.isNil, showFavoritesInHome {
LazyVStack(alignment: .leading) {
VStack(alignment: .leading) {
#if os(tvOS)
ForEach(Defaults[.favorites]) { item in
FavoriteItemView(item: item)
@@ -96,87 +106,6 @@ struct HomeView: View {
}
}
#if os(iOS)
if homeRecentDocumentsItems > 0 {
VStack {
HStack {
NavigationLink(destination: DocumentsView()) {
HStack {
Text("Documents")
.font(.title3.bold())
Image(systemName: "chevron.right")
.imageScale(.small)
}
.lineLimit(1)
}
.padding(.leading, 15)
Spacer()
Button {
recentDocumentsID = UUID()
} label: {
Label("Refresh", systemImage: "arrow.clockwise")
.font(.headline)
.labelStyle(.iconOnly)
.foregroundColor(.secondary)
}
}
RecentDocumentsView(limit: homeRecentDocumentsItems)
.id(recentDocumentsID)
}
.frame(maxWidth: .infinity, alignment: .leading)
#if os(tvOS)
.padding(.trailing, 40)
#else
.padding(.trailing, 15)
#endif
}
#endif
if homeHistoryItems > 0 {
VStack {
HStack {
sectionLabel("History")
Spacer()
Button {
navigation.presentAlert(
Alert(
title: Text("Are you sure you want to clear history of watched videos?"),
message: Text("This cannot be reverted"),
primaryButton: .destructive(Text("Clear All")) {
PlayerModel.shared.removeHistory()
historyID = UUID()
},
secondaryButton: .cancel()
)
)
} label: {
Label("Clear History", systemImage: "trash")
.font(.headline)
.labelStyle(.iconOnly)
.foregroundColor(.secondary)
}
.buttonStyle(.plain)
}
.frame(maxWidth: .infinity, alignment: .leading)
#if os(tvOS)
.padding(.trailing, 40)
#else
.padding(.trailing, 15)
#endif
HistoryView(limit: homeHistoryItems)
#if os(tvOS)
.padding(.horizontal, 40)
#else
.padding(.horizontal, 15)
#endif
.id(historyID)
}
}
#if !os(tvOS)
Color.clear.padding(.bottom, 60)
#endif
@@ -186,6 +115,10 @@ struct HomeView: View {
favoritesChanged.toggle()
}
.tieToLifetime(of: accounts)
Defaults.observe(.widgetsSettings) { _ in
favoritesChanged.toggle()
}
.tieToLifetime(of: accounts)
}
.redrawOn(change: favoritesChanged)
@@ -198,6 +131,13 @@ struct HomeView: View {
#if os(macOS)
.background(Color.secondaryBackground)
.frame(minWidth: 360)
.toolbar {
ToolbarItemGroup(placement: .automatic) {
HideWatchedButtons()
HideShortsButtons()
HomeSettingsButton()
}
}
#endif
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
@@ -226,13 +166,20 @@ struct HomeView: View {
.foregroundColor(.secondary)
}
#if os(iOS)
#if os(iOS)
var homeMenu: some View {
Menu {
Section {
HideWatchedButtons()
HideShortsButtons()
}
Section {
Button {
navigation.presentingHomeSettings = true
} label: {
Label("Home Settings", systemImage: "gear")
}
}
} label: {
HStack(spacing: 12) {
Text("Home")