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

130 lines
4.3 KiB
Swift
Raw Normal View History

import AppAccount
import DesignSystem
import Env
import Models
import Network
import NukeUI
import SwiftUI
import UserNotifications
2023-09-19 07:18:20 +00:00
@MainActor
struct ContentSettingsView: View {
2023-09-19 07:18:20 +00:00
@Environment(UserPreferences.self) private var userPreferences
2023-09-18 19:03:52 +00:00
@Environment(Theme.self) private var theme
2023-01-27 19:36:40 +00:00
var body: some View {
2023-09-19 07:18:20 +00:00
@Bindable var userPreferences = userPreferences
Form {
Section("settings.content.boosts") {
Toggle(isOn: $userPreferences.suppressDupeReblogs) {
Text("settings.content.hide-repeated-boosts")
}
2023-12-19 08:48:12 +00:00
}
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#endif
Section("settings.content.media") {
Toggle(isOn: $userPreferences.autoPlayVideo) {
Text("settings.other.autoplay-video")
}
Toggle(isOn: $userPreferences.showAltTextForMedia) {
2023-02-18 06:26:48 +00:00
Text("settings.content.media.show.alt")
}
2023-12-19 08:48:12 +00:00
}
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
#endif
2023-07-19 05:46:25 +00: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)
}
}
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
Section("settings.content.instance-settings") {
Toggle(isOn: $userPreferences.useInstanceContentSettings) {
Text("settings.content.use-instance-settings")
}
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#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
}
}
2023-01-27 19:36:40 +00:00
Section {
Toggle(isOn: $userPreferences.appAutoExpandSpoilers) {
Text("settings.content.expand-spoilers")
}
.disabled(userPreferences.useInstanceContentSettings)
2023-03-13 12:38:28 +00: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 12:38:28 +00:00
Toggle(isOn: $userPreferences.collapseLongPosts) {
Text("settings.content.collapse-long-posts")
}
} header: {
Text("settings.content.reading")
} footer: {
Text("settings.content.collapse-long-posts-hint")
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
2023-01-27 19:36:40 +00: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 12:15:03 +00:00
Picker("settings.content.default-reply-visibility", selection: $userPreferences.appDefaultReplyVisibility) {
ForEach(Visibility.allCases, id: \.rawValue) { vis in
if UserPreferences.getIntOfVisibility(vis) <=
2023-09-16 12:15:03 +00:00
UserPreferences.getIntOfVisibility(userPreferences.postVisibility)
{
Text(vis.title).tag(vis)
}
}
}
.onChange(of: userPreferences.postVisibility) {
userPreferences.conformReplyVisibilityConstraints()
}
2023-09-16 12:15:03 +00:00
Toggle(isOn: $userPreferences.appDefaultPostsSensitive) {
Text("settings.content.default-sensitive")
}
.disabled(userPreferences.useInstanceContentSettings)
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
}
.navigationTitle("settings.content.navigation-title")
2023-12-18 15:51:02 +00:00
#if !os(visionOS)
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
2023-12-18 15:51:02 +00:00
#endif
}
}