yattee/Shared/Settings/BrowsingSettings.swift

253 lines
9.2 KiB
Swift
Raw Normal View History

2021-11-04 23:25:51 +00:00
import Defaults
import SwiftUI
struct BrowsingSettings: View {
#if !os(tvOS)
@Default(.accountPickerDisplaysUsername) private var accountPickerDisplaysUsername
@Default(.roundedThumbnails) private var roundedThumbnails
#endif
@Default(.accountPickerDisplaysAnonymousAccounts) private var accountPickerDisplaysAnonymousAccounts
@Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges
#if os(iOS)
@Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing
@Default(.showDocuments) private var showDocuments
#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(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
@Default(.visibleSections) private var visibleSections
2023-05-25 15:01:53 +00:00
@Default(.startupSection) private var startupSection
@Default(.playerButtonSingleTapGesture) private var playerButtonSingleTapGesture
@Default(.playerButtonDoubleTapGesture) private var playerButtonDoubleTapGesture
@Default(.playerButtonShowsControlButtonsWhenMinimized) private var playerButtonShowsControlButtonsWhenMinimized
2022-12-19 00:37:09 +00:00
@Default(.playerButtonIsExpanded) private var playerButtonIsExpanded
@Default(.playerBarMaxWidth) private var playerBarMaxWidth
@Default(.expandChannelDescription) private var expandChannelDescription
2021-11-04 23:25:51 +00:00
@ObservedObject private var accounts = AccountsModel.shared
2022-11-11 20:28:40 +00:00
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)
2023-05-25 12:28:29 +00:00
@State private var presentingHomeSettingsSheet = false
2022-11-12 00:47:31 +00:00
#endif
2022-11-11 20:28:40 +00:00
2021-11-04 23:25:51 +00:00
var body: some View {
Group {
#if os(macOS)
2022-11-11 20:28:40 +00:00
VStack(alignment: .leading) {
sections
Spacer()
}
#else
List {
sections
}
#if os(iOS)
.listStyle(.insetGrouped)
#endif
#endif
}
#if os(tvOS)
2023-05-25 15:01:53 +00:00
.frame(maxWidth: 1200)
#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
2023-05-25 15:01:53 +00:00
if !accounts.isEmpty {
startupSectionPicker
visibleSectionsSettings
}
let interface = interfaceSettings
#if os(tvOS)
if !accounts.isEmpty {
interface
}
#else
interface
2023-05-25 15:01:53 +00:00
playerBarSettings
#endif
2022-11-11 20:28:40 +00:00
if !accounts.isEmpty {
thumbnailsSettings
}
}
}
2023-05-25 12:28:29 +00:00
@ViewBuilder private var homeSettings: some View {
if !accounts.isEmpty {
2023-05-25 15:01:53 +00:00
Section {
2023-05-25 12:28:29 +00:00
#if os(macOS)
Button {
presentingHomeSettingsSheet = true
} label: {
Text("Home Settings")
}
.sheet(isPresented: $presentingHomeSettingsSheet) {
VStack(alignment: .leading) {
Button("Done") {
presentingHomeSettingsSheet = false
}
.padding()
.keyboardShortcut(.cancelAction)
2022-11-12 23:01:04 +00:00
2023-05-25 12:28:29 +00:00
HomeSettings()
}
2023-05-25 12:28:29 +00:00
.frame(width: 500, height: 800)
2022-11-19 11:54:37 +00:00
}
2023-05-25 12:28:29 +00:00
#else
NavigationLink(destination: LazyView(HomeSettings())) {
Text("Home Settings")
2022-11-19 11:54:37 +00:00
}
2023-05-25 12:28:29 +00:00
#endif
2022-11-12 00:47:31 +00:00
}
}
}
2021-11-07 20:51:22 +00:00
#if !os(tvOS)
private var playerBarSettings: some View {
Section(header: SettingsHeader(text: "Player Bar".localized()), footer: playerBarFooter) {
2022-12-19 00:37:09 +00:00
Toggle("Open expanded", isOn: $playerButtonIsExpanded)
Toggle("Always show controls buttons", isOn: $playerButtonShowsControlButtonsWhenMinimized)
2023-04-22 21:10:05 +00:00
playerBarGesturePicker("Single tap gesture".localized(), selection: $playerButtonSingleTapGesture)
playerBarGesturePicker("Double tap gesture".localized(), selection: $playerButtonDoubleTapGesture)
2022-12-19 00:37:09 +00:00
HStack {
Text("Maximum width expanded")
Spacer()
TextField("Maximum width expanded", text: $playerBarMaxWidth)
.frame(maxWidth: 100, alignment: .trailing)
.multilineTextAlignment(.trailing)
.labelsHidden()
#if !os(macOS)
.keyboardType(.numberPad)
#endif
}
}
}
func playerBarGesturePicker(_ label: String, selection: Binding<PlayerTapGestureAction>) -> some View {
Picker(label, selection: selection) {
ForEach(PlayerTapGestureAction.allCases, id: \.rawValue) { action in
2023-04-22 21:10:05 +00:00
Text(action.label.localized()).tag(action)
}
}
}
var playerBarFooter: some View {
#if os(iOS)
Text("Tap and hold channel thumbnail to open context menu with more actions")
#elseif os(macOS)
Text("Right click channel thumbnail to open context menu with more actions")
2022-12-19 12:35:37 +00:00
.foregroundColor(.secondary)
.padding(.bottom, 10)
#endif
}
#endif
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
#if os(iOS)
2022-11-12 23:01:04 +00:00
Toggle("Show Documents", isOn: $showDocuments)
Toggle("Lock portrait mode", isOn: $lockPortraitWhenBrowsing)
.onChange(of: lockPortraitWhenBrowsing) { lock in
if lock {
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
} else {
Orientation.lockOrientation(.allButUpsideDown)
}
}
#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-11-11 20:28:40 +00:00
Toggle("Show anonymous accounts", isOn: $accountPickerDisplaysAnonymousAccounts)
Toggle("Show unwatched feed badges", isOn: $showUnwatchedFeedBadges)
.onChange(of: showUnwatchedFeedBadges) { newValue in
if newValue {
FeedModel.shared.calculateUnwatchedFeed()
}
}
2022-11-11 20:28:40 +00:00
}
2022-12-19 00:37:09 +00:00
Toggle("Open channels with description expanded", isOn: $expandChannelDescription)
}
}
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
#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
}
private var visibleSectionsSettings: some View {
2022-09-04 15:28:30 +00:00
Section(header: SettingsHeader(text: "Sections".localized())) {
2023-05-25 15:01:53 +00:00
ForEach(VisibleSection.allCases, id: \.self) { section in
MultiselectRow(
title: section.title,
selected: visibleSections.contains(section)
) { value in
toggleSection(section, value: value)
}
2023-05-25 15:01:53 +00:00
}
}
}
2023-05-25 15:01:53 +00:00
private var startupSectionPicker: some View {
Group {
#if os(tvOS)
SettingsHeader(text: "Startup section".localized())
#endif
2023-05-25 15:01:53 +00:00
Picker("Startup section", selection: $startupSection) {
ForEach(StartupSection.allCases, id: \.rawValue) { section in
Text(section.label).tag(section)
}
}
.modifier(SettingsPickerModifier())
2021-11-04 23:25:51 +00:00
}
}
2021-11-07 20:51:22 +00:00
private func toggleSection(_ section: VisibleSection, value: Bool) {
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
}
}