2021-11-04 23:25:51 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct BrowsingSettings: View {
|
2022-01-02 19:34:50 +00:00
|
|
|
#if !os(tvOS)
|
|
|
|
@Default(.accountPickerDisplaysUsername) private var accountPickerDisplaysUsername
|
2022-01-06 14:56:59 +00:00
|
|
|
@Default(.roundedThumbnails) private var roundedThumbnails
|
2022-01-02 19:34:50 +00:00
|
|
|
#endif
|
2022-08-25 23:36:46 +00:00
|
|
|
@Default(.accountPickerDisplaysAnonymousAccounts) private var accountPickerDisplaysAnonymousAccounts
|
2022-01-02 19:41:04 +00:00
|
|
|
#if os(iOS)
|
2022-11-18 22:39:52 +00:00
|
|
|
@Default(.homeRecentDocumentsItems) private var homeRecentDocumentsItems
|
2022-01-02 19:41:04 +00:00
|
|
|
@Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing
|
2022-11-18 23:38:32 +00:00
|
|
|
@Default(.showDocuments) private var showDocuments
|
2022-01-02 19:41:04 +00:00
|
|
|
#endif
|
2022-06-26 12:25:54 +00:00
|
|
|
@Default(.thumbnailsQuality) private var thumbnailsQuality
|
2021-11-04 23:25:51 +00:00
|
|
|
@Default(.channelOnThumbnail) private var channelOnThumbnail
|
|
|
|
@Default(.timeOnThumbnail) private var timeOnThumbnail
|
2022-11-11 20:28:40 +00:00
|
|
|
@Default(.showHome) private var showHome
|
|
|
|
@Default(.showFavoritesInHome) private var showFavoritesInHome
|
|
|
|
@Default(.showOpenActionsInHome) private var showOpenActionsInHome
|
|
|
|
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
|
|
|
|
@Default(.homeHistoryItems) private var homeHistoryItems
|
2021-12-01 11:22:19 +00:00
|
|
|
@Default(.visibleSections) private var visibleSections
|
2021-11-04 23:25:51 +00:00
|
|
|
|
2022-11-11 20:28:40 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
|
|
|
|
|
|
|
@State private var homeHistoryItemsText = ""
|
2022-11-18 22:39:52 +00:00
|
|
|
#if os(iOS)
|
|
|
|
@State private var homeRecentDocumentsItemsText = ""
|
|
|
|
#endif
|
2022-11-12 00:47:31 +00:00
|
|
|
#if os(macOS)
|
|
|
|
@State private var presentingEditFavoritesSheet = false
|
|
|
|
#endif
|
2022-11-11 20:28:40 +00:00
|
|
|
|
2021-11-04 23:25:51 +00:00
|
|
|
var body: some View {
|
2021-12-01 11:22:19 +00:00
|
|
|
Group {
|
2022-01-06 14:56:59 +00:00
|
|
|
#if os(macOS)
|
2022-11-11 20:28:40 +00:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
sections
|
|
|
|
Spacer()
|
|
|
|
}
|
2022-01-06 14:56:59 +00:00
|
|
|
#else
|
|
|
|
List {
|
|
|
|
sections
|
|
|
|
}
|
2022-01-02 19:41:04 +00:00
|
|
|
#if os(iOS)
|
2022-01-06 14:56:59 +00:00
|
|
|
.listStyle(.insetGrouped)
|
2022-01-02 19:41:04 +00:00
|
|
|
#endif
|
2022-01-06 14:56:59 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.frame(maxWidth: 1000)
|
|
|
|
#else
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
|
|
|
#endif
|
|
|
|
.navigationTitle("Browsing")
|
|
|
|
}
|
|
|
|
|
|
|
|
private var sections: some View {
|
|
|
|
Group {
|
2022-11-11 20:28:40 +00:00
|
|
|
homeSettings
|
2022-11-18 23:38:32 +00:00
|
|
|
let interface = interfaceSettings
|
|
|
|
#if os(tvOS)
|
|
|
|
if !accounts.isEmpty {
|
|
|
|
interface
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
interface
|
|
|
|
#endif
|
2022-11-11 20:28:40 +00:00
|
|
|
if !accounts.isEmpty {
|
|
|
|
thumbnailsSettings
|
|
|
|
visibleSectionsSettings
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var homeSettings: some View {
|
|
|
|
Section(header: SettingsHeader(text: "Home".localized())) {
|
|
|
|
#if !os(tvOS)
|
|
|
|
if !accounts.isEmpty {
|
|
|
|
Toggle("Show Home", isOn: $showHome)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
Toggle("Show Open Videos quick actions", isOn: $showOpenActionsInHome)
|
2022-11-12 23:01:04 +00:00
|
|
|
|
2022-11-18 23:38:32 +00:00
|
|
|
#if os(iOS)
|
|
|
|
HStack {
|
|
|
|
Text("Recent Documents")
|
|
|
|
TextField("Recent Documents", text: $homeRecentDocumentsItemsText)
|
2022-11-19 11:54:37 +00:00
|
|
|
.multilineTextAlignment(.trailing)
|
2022-11-18 23:38:32 +00:00
|
|
|
.labelsHidden()
|
|
|
|
#if !os(macOS)
|
|
|
|
.keyboardType(.numberPad)
|
|
|
|
#endif
|
|
|
|
.onAppear {
|
|
|
|
homeRecentDocumentsItemsText = String(homeRecentDocumentsItems)
|
|
|
|
}
|
|
|
|
.onChange(of: homeRecentDocumentsItemsText) { newValue in
|
|
|
|
homeRecentDocumentsItems = Int(newValue) ?? 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2022-11-18 22:39:52 +00:00
|
|
|
|
2022-11-19 11:54:37 +00:00
|
|
|
HStack {
|
|
|
|
Text("Recent History")
|
|
|
|
TextField("Recent History", text: $homeHistoryItemsText)
|
|
|
|
.multilineTextAlignment(.trailing)
|
|
|
|
.labelsHidden()
|
|
|
|
#if !os(macOS)
|
|
|
|
.keyboardType(.numberPad)
|
|
|
|
#endif
|
|
|
|
.onAppear {
|
|
|
|
homeHistoryItemsText = String(homeHistoryItems)
|
|
|
|
}
|
|
|
|
.onChange(of: homeHistoryItemsText) { newValue in
|
|
|
|
homeHistoryItems = Int(newValue) ?? 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-12 00:47:31 +00:00
|
|
|
if !accounts.isEmpty {
|
|
|
|
Toggle("Show Favorites", isOn: $showFavoritesInHome)
|
|
|
|
|
|
|
|
Group {
|
|
|
|
#if os(macOS)
|
|
|
|
Button {
|
|
|
|
presentingEditFavoritesSheet = true
|
|
|
|
} label: {
|
2022-11-18 23:38:32 +00:00
|
|
|
Text("Edit Favorites…")
|
2022-11-12 00:47:31 +00:00
|
|
|
}
|
|
|
|
.sheet(isPresented: $presentingEditFavoritesSheet) {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Button("Done") {
|
|
|
|
presentingEditFavoritesSheet = false
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
.keyboardShortcut(.cancelAction)
|
|
|
|
|
|
|
|
EditFavorites()
|
|
|
|
}
|
|
|
|
.frame(width: 500, height: 300)
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
NavigationLink(destination: LazyView(EditFavorites())) {
|
2022-11-18 23:06:13 +00:00
|
|
|
Text("Edit Favorites…")
|
2022-11-12 00:47:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.disabled(!showFavoritesInHome)
|
|
|
|
}
|
2022-01-06 14:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-07 20:51:22 +00:00
|
|
|
|
2022-01-06 14:56:59 +00:00
|
|
|
private var interfaceSettings: some View {
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "Interface".localized())) {
|
2022-11-12 01:39:44 +00:00
|
|
|
#if !os(tvOS)
|
|
|
|
Toggle("Show Open Videos toolbar button", isOn: $showOpenActionsToolbarItem)
|
|
|
|
#endif
|
2022-01-06 14:56:59 +00:00
|
|
|
#if os(iOS)
|
2022-11-12 23:01:04 +00:00
|
|
|
Toggle("Show Documents", isOn: $showDocuments)
|
|
|
|
|
2022-01-06 14:56:59 +00:00
|
|
|
Toggle("Lock portrait mode", isOn: $lockPortraitWhenBrowsing)
|
|
|
|
.onChange(of: lockPortraitWhenBrowsing) { lock in
|
|
|
|
if lock {
|
|
|
|
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
2021-12-01 11:22:19 +00:00
|
|
|
} else {
|
2022-01-06 14:56:59 +00:00
|
|
|
Orientation.lockOrientation(.allButUpsideDown)
|
2021-12-01 11:22:19 +00:00
|
|
|
}
|
2022-01-06 14:56:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
2021-12-02 19:22:55 +00:00
|
|
|
|
2022-11-11 20:28:40 +00:00
|
|
|
if !accounts.isEmpty {
|
|
|
|
#if !os(tvOS)
|
|
|
|
Toggle("Show account username", isOn: $accountPickerDisplaysUsername)
|
|
|
|
#endif
|
2022-08-25 23:36:46 +00:00
|
|
|
|
2022-11-11 20:28:40 +00:00
|
|
|
Toggle("Show anonymous accounts", isOn: $accountPickerDisplaysAnonymousAccounts)
|
|
|
|
}
|
2022-01-06 14:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var thumbnailsSettings: some View {
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "Thumbnails".localized())) {
|
2022-06-26 12:25:54 +00:00
|
|
|
thumbnailsQualityPicker
|
2022-01-06 14:56:59 +00:00
|
|
|
#if !os(tvOS)
|
|
|
|
Toggle("Round corners", isOn: $roundedThumbnails)
|
|
|
|
#endif
|
|
|
|
Toggle("Show channel name", isOn: $channelOnThumbnail)
|
|
|
|
Toggle("Show video length", isOn: $timeOnThumbnail)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-26 12:25:54 +00:00
|
|
|
private var thumbnailsQualityPicker: some View {
|
|
|
|
Picker("Quality", selection: $thumbnailsQuality) {
|
|
|
|
ForEach(ThumbnailsQuality.allCases, id: \.self) { quality in
|
2022-09-04 15:28:30 +00:00
|
|
|
Text(quality.description)
|
2022-06-26 12:25:54 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-06 14:28:05 +00:00
|
|
|
.modifier(SettingsPickerModifier())
|
2022-06-26 12:25:54 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 14:56:59 +00:00
|
|
|
private var visibleSectionsSettings: some View {
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "Sections".localized())) {
|
2022-01-06 14:56:59 +00:00
|
|
|
#if os(macOS)
|
|
|
|
let list = ForEach(VisibleSection.allCases, id: \.self) { section in
|
2022-11-11 18:53:52 +00:00
|
|
|
MultiselectRow(
|
2022-01-06 14:56:59 +00:00
|
|
|
title: section.title,
|
|
|
|
selected: visibleSections.contains(section)
|
|
|
|
) { value in
|
|
|
|
toggleSection(section, value: value)
|
2021-12-01 11:22:19 +00:00
|
|
|
}
|
2022-01-06 14:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Group {
|
|
|
|
if #available(macOS 12.0, *) {
|
|
|
|
list
|
|
|
|
.listStyle(.inset(alternatesRowBackgrounds: true))
|
|
|
|
} else {
|
|
|
|
list
|
|
|
|
.listStyle(.inset)
|
2021-12-01 11:22:19 +00:00
|
|
|
}
|
2022-01-06 14:56:59 +00:00
|
|
|
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
ForEach(VisibleSection.allCases, id: \.self) { section in
|
2022-11-11 18:53:52 +00:00
|
|
|
MultiselectRow(
|
2022-01-06 14:56:59 +00:00
|
|
|
title: section.title,
|
|
|
|
selected: visibleSections.contains(section)
|
|
|
|
) { value in
|
|
|
|
toggleSection(section, value: value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-11-04 23:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-07 20:51:22 +00:00
|
|
|
|
2022-01-06 14:56:59 +00:00
|
|
|
private func toggleSection(_ section: VisibleSection, value: Bool) {
|
2021-12-01 11:22:19 +00:00
|
|
|
if value {
|
|
|
|
visibleSections.insert(section)
|
|
|
|
} else {
|
|
|
|
visibleSections.remove(section)
|
|
|
|
}
|
2021-11-07 20:51:22 +00:00
|
|
|
}
|
2021-11-04 23:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct BrowsingSettings_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-11-11 18:53:52 +00:00
|
|
|
VStack {
|
|
|
|
BrowsingSettings()
|
|
|
|
}
|
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-11-04 23:25:51 +00:00
|
|
|
}
|
|
|
|
}
|