IceCubes/IceCubesApp/App/Tabs/Settings/ContentSettingsView.swift

150 lines
5.2 KiB
Swift
Raw Normal View History

import AppAccount
import DesignSystem
import Env
import Models
import Network
import NukeUI
import SwiftUI
2024-01-11 18:55:35 +01:00
import Timeline
2024-02-14 12:48:14 +01:00
import UserNotifications
2023-09-19 09:18:20 +02:00
@MainActor
struct ContentSettingsView: View {
2023-09-19 09:18:20 +02:00
@Environment(UserPreferences.self) private var userPreferences
2023-09-18 21:03:52 +02:00
@Environment(Theme.self) private var theme
2024-02-14 12:48:14 +01:00
2024-01-11 18:55:35 +01:00
@State private var contentFilter = TimelineContentFilter.shared
2023-01-27 20:36:40 +01:00
var body: some View {
2023-09-19 09:18:20 +02:00
@Bindable var userPreferences = userPreferences
Form {
Section("settings.content.media") {
Toggle(isOn: $userPreferences.autoPlayVideo) {
Text("settings.other.autoplay-video")
}
2024-01-07 17:33:37 +01:00
Toggle(isOn: $userPreferences.muteVideo) {
Text("settings.other.mute-video")
}
Toggle(isOn: $userPreferences.showAltTextForMedia) {
2023-02-18 07:26:48 +01:00
Text("settings.content.media.show.alt")
}
}
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#endif
2023-07-19 07:46:25 +02:00
Section("settings.content.sharing") {
Picker("settings.content.sharing.share-button-behavior", selection: $userPreferences.shareButtonBehavior) {
ForEach(PreferredShareButtonBehavior.allCases, id: \.rawValue) { option in
Text(option.title)
.tag(option)
}
}
}
2024-02-14 12:48:14 +01:00
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#endif
Section("settings.content.instance-settings") {
Toggle(isOn: $userPreferences.useInstanceContentSettings) {
Text("settings.content.use-instance-settings")
}
}
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#endif
.onChange(of: userPreferences.useInstanceContentSettings) { _, newVal in
if newVal {
userPreferences.appAutoExpandSpoilers = userPreferences.autoExpandSpoilers
userPreferences.appAutoExpandMedia = userPreferences.autoExpandMedia
userPreferences.appDefaultPostsSensitive = userPreferences.postIsSensitive
userPreferences.appDefaultPostVisibility = userPreferences.postVisibility
userPreferences.appRequireAltText = userPreferences.appRequireAltText
}
}
2023-01-27 20:36:40 +01:00
Section {
Toggle(isOn: $userPreferences.appAutoExpandSpoilers) {
Text("settings.content.expand-spoilers")
}
.disabled(userPreferences.useInstanceContentSettings)
2023-03-13 13:38:28 +01:00
Picker("settings.content.expand-media", selection: $userPreferences.appAutoExpandMedia) {
ForEach(ServerPreferences.AutoExpandMedia.allCases, id: \.rawValue) { media in
Text(media.description).tag(media)
}
}
.disabled(userPreferences.useInstanceContentSettings)
2023-03-13 13:38:28 +01:00
Toggle(isOn: $userPreferences.collapseLongPosts) {
Text("settings.content.collapse-long-posts")
}
} header: {
Text("settings.content.reading")
} footer: {
Text("settings.content.collapse-long-posts-hint")
}
2024-01-11 18:55:35 +01:00
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#endif
2023-01-27 20:36:40 +01:00
Section("settings.content.posting") {
Picker("settings.content.default-visibility", selection: $userPreferences.appDefaultPostVisibility) {
ForEach(Visibility.allCases, id: \.rawValue) { vis in
Text(vis.title).tag(vis)
}
}
.disabled(userPreferences.useInstanceContentSettings)
2023-09-16 14:15:03 +02:00
Picker("settings.content.default-reply-visibility", selection: $userPreferences.appDefaultReplyVisibility) {
ForEach(Visibility.allCases, id: \.rawValue) { vis in
if UserPreferences.getIntOfVisibility(vis) <=
2023-09-16 14:15:03 +02:00
UserPreferences.getIntOfVisibility(userPreferences.postVisibility)
{
Text(vis.title).tag(vis)
}
}
}
.onChange(of: userPreferences.postVisibility) {
userPreferences.conformReplyVisibilityConstraints()
}
2023-09-16 14:15:03 +02:00
Toggle(isOn: $userPreferences.appDefaultPostsSensitive) {
Text("settings.content.default-sensitive")
}
.disabled(userPreferences.useInstanceContentSettings)
2024-02-14 12:48:14 +01:00
Toggle(isOn: $userPreferences.appRequireAltText) {
Text("settings.content.require-alt-text")
}
}
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#endif
2024-02-14 12:48:14 +01:00
2024-01-11 18:55:35 +01:00
Section("timeline.content-filter.title") {
Toggle(isOn: $contentFilter.showBoosts) {
Label("timeline.filter.show-boosts", image: "Rocket")
}
Toggle(isOn: $contentFilter.showReplies) {
Label("timeline.filter.show-replies", systemImage: "bubble.left.and.bubble.right")
}
Toggle(isOn: $contentFilter.showThreads) {
Label("timeline.filter.show-threads", systemImage: "bubble.left.and.text.bubble.right")
}
Toggle(isOn: $contentFilter.showQuotePosts) {
Label("timeline.filter.show-quote", systemImage: "quote.bubble")
}
}
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#endif
}
.navigationTitle("settings.content.navigation-title")
#if !os(visionOS)
2024-02-14 12:48:14 +01:00
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
#endif
}
}