2023-03-13 13:38:28 +01:00
|
|
|
import Combine
|
2023-01-06 17:14:34 +01:00
|
|
|
import DesignSystem
|
2023-01-22 06:38:30 +01:00
|
|
|
import Env
|
2023-01-17 11:36:01 +01:00
|
|
|
import Models
|
2023-02-18 07:26:48 +01:00
|
|
|
import Network
|
2023-09-18 07:01:23 +02:00
|
|
|
import Observation
|
2024-01-06 19:27:26 +01:00
|
|
|
import StatusKit
|
2023-01-17 11:36:01 +01:00
|
|
|
import SwiftUI
|
2023-03-08 19:02:00 +01:00
|
|
|
|
2024-03-11 08:59:29 +01:00
|
|
|
@MainActor
|
2023-09-18 07:01:23 +02:00
|
|
|
@Observable class DisplaySettingsLocalValues {
|
|
|
|
var tintColor = Theme.shared.tintColor
|
|
|
|
var primaryBackgroundColor = Theme.shared.primaryBackgroundColor
|
|
|
|
var secondaryBackgroundColor = Theme.shared.secondaryBackgroundColor
|
|
|
|
var labelColor = Theme.shared.labelColor
|
|
|
|
var lineSpacing = Theme.shared.lineSpacing
|
|
|
|
var fontSizeScale = Theme.shared.fontSizeScale
|
2023-03-08 19:02:00 +01:00
|
|
|
}
|
2023-01-06 17:14:34 +01:00
|
|
|
|
2023-09-19 09:18:20 +02:00
|
|
|
@MainActor
|
2023-01-06 17:14:34 +01:00
|
|
|
struct DisplaySettingsView: View {
|
2023-01-30 07:27:06 +01:00
|
|
|
typealias FontState = Theme.FontState
|
2023-02-09 06:22:34 +01:00
|
|
|
|
2023-01-22 16:59:56 +01:00
|
|
|
@Environment(\.colorScheme) private var colorScheme
|
2023-09-18 21:03:52 +02:00
|
|
|
@Environment(Theme.self) private var theme
|
2023-09-19 09:18:20 +02:00
|
|
|
@Environment(UserPreferences.self) private var userPreferences
|
2023-03-13 13:38:28 +01:00
|
|
|
|
2023-09-18 07:01:23 +02:00
|
|
|
@State private var localValues = DisplaySettingsLocalValues()
|
2023-02-09 06:22:34 +01:00
|
|
|
|
2023-01-30 07:27:06 +01:00
|
|
|
@State private var isFontSelectorPresented = false
|
2023-03-13 13:38:28 +01:00
|
|
|
|
2023-03-08 19:02:00 +01:00
|
|
|
private let previewStatusViewModel = StatusRowViewModel(status: Status.placeholder(forSettings: true, language: "la"),
|
2023-02-15 08:46:14 +01:00
|
|
|
client: Client(server: ""),
|
|
|
|
routerPath: RouterPath()) // translate from latin button
|
2023-03-13 13:38:28 +01:00
|
|
|
|
2023-01-06 17:14:34 +01:00
|
|
|
var body: some View {
|
2023-03-26 19:19:59 +02:00
|
|
|
ZStack(alignment: .top) {
|
|
|
|
Form {
|
2024-01-21 11:13:25 +01:00
|
|
|
#if !os(visionOS)
|
2024-02-14 12:48:14 +01:00
|
|
|
StatusRowView(viewModel: previewStatusViewModel)
|
|
|
|
.allowsHitTesting(false)
|
|
|
|
.opacity(0)
|
|
|
|
.hidden()
|
|
|
|
themeSection
|
2024-01-21 11:13:25 +01:00
|
|
|
#endif
|
2023-03-26 19:19:59 +02:00
|
|
|
fontSection
|
|
|
|
layoutSection
|
|
|
|
platformsSection
|
|
|
|
resetSection
|
|
|
|
}
|
|
|
|
.navigationTitle("settings.display.navigation-title")
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2024-02-14 12:48:14 +01:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2024-02-14 12:48:14 +01:00
|
|
|
.task(id: localValues.tintColor) {
|
|
|
|
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
|
|
|
theme.tintColor = localValues.tintColor
|
|
|
|
}
|
|
|
|
.task(id: localValues.primaryBackgroundColor) {
|
|
|
|
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
|
|
|
theme.primaryBackgroundColor = localValues.primaryBackgroundColor
|
|
|
|
}
|
|
|
|
.task(id: localValues.secondaryBackgroundColor) {
|
|
|
|
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
|
|
|
theme.secondaryBackgroundColor = localValues.secondaryBackgroundColor
|
|
|
|
}
|
|
|
|
.task(id: localValues.labelColor) {
|
|
|
|
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
|
|
|
theme.labelColor = localValues.labelColor
|
|
|
|
}
|
|
|
|
.task(id: localValues.lineSpacing) {
|
|
|
|
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
|
|
|
theme.lineSpacing = localValues.lineSpacing
|
|
|
|
}
|
|
|
|
.task(id: localValues.fontSizeScale) {
|
|
|
|
do { try await Task.sleep(for: .microseconds(500)) } catch {}
|
|
|
|
theme.fontSizeScale = localValues.fontSizeScale
|
|
|
|
}
|
2024-01-21 11:13:25 +01:00
|
|
|
#if !os(visionOS)
|
2024-02-14 12:48:14 +01:00
|
|
|
examplePost
|
2024-01-21 11:13:25 +01:00
|
|
|
#endif
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-13 13:38:28 +01:00
|
|
|
|
2023-03-26 19:19:59 +02:00
|
|
|
private var examplePost: some View {
|
|
|
|
VStack(spacing: 0) {
|
2023-09-18 07:01:23 +02:00
|
|
|
StatusRowView(viewModel: previewStatusViewModel)
|
2023-03-03 08:29:45 +01:00
|
|
|
.allowsHitTesting(false)
|
2023-03-26 19:19:59 +02:00
|
|
|
.padding(.layoutPadding)
|
|
|
|
.background(theme.primaryBackgroundColor)
|
|
|
|
.cornerRadius(8)
|
|
|
|
.padding(.horizontal, .layoutPadding)
|
|
|
|
.padding(.top, .layoutPadding)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
|
|
|
Rectangle()
|
|
|
|
.fill(theme.secondaryBackgroundColor)
|
|
|
|
.frame(height: 30)
|
|
|
|
.mask(LinearGradient(gradient: Gradient(colors: [theme.secondaryBackgroundColor, .clear]),
|
|
|
|
startPoint: .top, endPoint: .bottom))
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-13 13:38:28 +01:00
|
|
|
|
2023-09-18 21:03:52 +02:00
|
|
|
@ViewBuilder
|
2023-03-03 08:29:45 +01:00
|
|
|
private var themeSection: some View {
|
2023-09-18 21:03:52 +02:00
|
|
|
@Bindable var theme = theme
|
2023-03-03 08:29:45 +01:00
|
|
|
Section {
|
|
|
|
Toggle("settings.display.theme.systemColor", isOn: $theme.followSystemColorScheme)
|
|
|
|
themeSelectorButton
|
|
|
|
Group {
|
2023-03-31 15:34:24 +02:00
|
|
|
ColorPicker("settings.display.theme.tint", selection: $localValues.tintColor)
|
|
|
|
ColorPicker("settings.display.theme.background", selection: $localValues.primaryBackgroundColor)
|
|
|
|
ColorPicker("settings.display.theme.secondary-background", selection: $localValues.secondaryBackgroundColor)
|
|
|
|
ColorPicker("settings.display.theme.text-color", selection: $localValues.labelColor)
|
2023-02-08 19:09:24 +01:00
|
|
|
}
|
2023-03-03 08:29:45 +01:00
|
|
|
.disabled(theme.followSystemColorScheme)
|
|
|
|
.opacity(theme.followSystemColorScheme ? 0.5 : 1.0)
|
2023-09-18 07:01:23 +02:00
|
|
|
.onChange(of: theme.selectedSet) {
|
2023-03-31 15:34:24 +02:00
|
|
|
localValues.tintColor = theme.tintColor
|
|
|
|
localValues.primaryBackgroundColor = theme.primaryBackgroundColor
|
|
|
|
localValues.secondaryBackgroundColor = theme.secondaryBackgroundColor
|
|
|
|
localValues.labelColor = theme.labelColor
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
|
|
|
} header: {
|
|
|
|
Text("settings.display.section.theme")
|
|
|
|
} footer: {
|
|
|
|
if theme.followSystemColorScheme {
|
|
|
|
Text("settings.display.section.theme.footer")
|
|
|
|
}
|
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2023-03-03 08:29:45 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
2023-03-13 13:38:28 +01:00
|
|
|
|
2023-03-03 08:29:45 +01:00
|
|
|
private var fontSection: some View {
|
|
|
|
Section("settings.display.section.font") {
|
|
|
|
Picker("settings.display.font", selection: .init(get: { () -> FontState in
|
|
|
|
if theme.chosenFont?.fontName == "OpenDyslexic-Regular" {
|
|
|
|
return FontState.openDyslexic
|
|
|
|
} else if theme.chosenFont?.fontName == "AtkinsonHyperlegible-Regular" {
|
|
|
|
return FontState.hyperLegible
|
|
|
|
} else if theme.chosenFont?.fontName == ".AppleSystemUIFontRounded-Regular" {
|
|
|
|
return FontState.SFRounded
|
|
|
|
}
|
|
|
|
return theme.chosenFontData != nil ? FontState.custom : FontState.system
|
|
|
|
}, set: { newValue in
|
|
|
|
switch newValue {
|
|
|
|
case .system:
|
|
|
|
theme.chosenFont = nil
|
|
|
|
case .openDyslexic:
|
|
|
|
theme.chosenFont = UIFont(name: "OpenDyslexic", size: 1)
|
|
|
|
case .hyperLegible:
|
|
|
|
theme.chosenFont = UIFont(name: "Atkinson Hyperlegible", size: 1)
|
|
|
|
case .SFRounded:
|
|
|
|
theme.chosenFont = UIFont.systemFont(ofSize: 1).rounded()
|
|
|
|
case .custom:
|
|
|
|
isFontSelectorPresented = true
|
|
|
|
}
|
|
|
|
})) {
|
|
|
|
ForEach(FontState.allCases, id: \.rawValue) { fontState in
|
|
|
|
Text(fontState.title).tag(fontState)
|
2023-02-15 20:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-03 08:29:45 +01:00
|
|
|
.navigationDestination(isPresented: $isFontSelectorPresented, destination: { FontPicker() })
|
2023-02-18 07:26:48 +01:00
|
|
|
|
2023-03-03 08:29:45 +01:00
|
|
|
VStack {
|
2023-03-31 15:34:24 +02:00
|
|
|
Slider(value: $localValues.fontSizeScale, in: 0.5 ... 1.5, step: 0.1)
|
|
|
|
Text("settings.display.font.scaling-\(String(format: "%.1f", localValues.fontSizeScale))")
|
2023-03-03 08:29:45 +01:00
|
|
|
.font(.scaledBody)
|
|
|
|
}
|
|
|
|
.alignmentGuide(.listRowSeparatorLeading) { d in
|
|
|
|
d[.leading]
|
|
|
|
}
|
2023-03-31 15:34:24 +02:00
|
|
|
|
2023-03-26 18:51:15 +02:00
|
|
|
VStack {
|
2023-03-31 15:34:24 +02:00
|
|
|
Slider(value: $localValues.lineSpacing, in: 0.4 ... 10.0, step: 0.2)
|
|
|
|
Text("settings.display.font.line-spacing-\(String(format: "%.1f", localValues.lineSpacing))")
|
2023-03-26 18:51:15 +02:00
|
|
|
.font(.scaledBody)
|
|
|
|
}
|
|
|
|
.alignmentGuide(.listRowSeparatorLeading) { d in
|
|
|
|
d[.leading]
|
|
|
|
}
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2023-03-03 08:29:45 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
2023-03-13 13:38:28 +01:00
|
|
|
|
2023-09-18 21:03:52 +02:00
|
|
|
@ViewBuilder
|
2023-03-03 08:29:45 +01:00
|
|
|
private var layoutSection: some View {
|
2023-09-18 21:03:52 +02:00
|
|
|
@Bindable var theme = theme
|
2023-09-19 09:18:20 +02:00
|
|
|
@Bindable var userPreferences = userPreferences
|
2023-03-03 08:29:45 +01:00
|
|
|
Section("settings.display.section.display") {
|
|
|
|
Picker("settings.display.avatar.position", selection: $theme.avatarPosition) {
|
|
|
|
ForEach(Theme.AvatarPosition.allCases, id: \.rawValue) { position in
|
|
|
|
Text(position.description).tag(position)
|
2023-01-06 17:14:34 +01:00
|
|
|
}
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
|
|
|
Picker("settings.display.avatar.shape", selection: $theme.avatarShape) {
|
|
|
|
ForEach(Theme.AvatarShape.allCases, id: \.rawValue) { shape in
|
|
|
|
Text(shape.description).tag(shape)
|
2023-01-07 17:44:25 +01:00
|
|
|
}
|
2023-01-06 17:14:34 +01:00
|
|
|
}
|
2023-03-03 08:29:45 +01:00
|
|
|
Toggle("settings.display.full-username", isOn: $theme.displayFullUsername)
|
|
|
|
Picker("settings.display.status.action-buttons", selection: $theme.statusActionsDisplay) {
|
|
|
|
ForEach(Theme.StatusActionsDisplay.allCases, id: \.rawValue) { buttonStyle in
|
|
|
|
Text(buttonStyle.description).tag(buttonStyle)
|
2023-02-09 06:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
2023-12-28 07:48:35 +01:00
|
|
|
Picker("settings.display.status.action-secondary", selection: $theme.statusActionSecondary) {
|
|
|
|
ForEach(Theme.StatusActionSecondary.allCases, id: \.rawValue) { action in
|
|
|
|
Text(action.description).tag(action)
|
|
|
|
}
|
|
|
|
}
|
2023-03-03 08:29:45 +01:00
|
|
|
Picker("settings.display.status.media-style", selection: $theme.statusDisplayStyle) {
|
|
|
|
ForEach(Theme.StatusDisplayStyle.allCases, id: \.rawValue) { buttonStyle in
|
|
|
|
Text(buttonStyle.description).tag(buttonStyle)
|
2023-02-06 18:53:37 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-03 08:29:45 +01:00
|
|
|
Toggle("settings.display.translate-button", isOn: $userPreferences.showTranslateButton)
|
2023-10-01 09:24:37 +02:00
|
|
|
Toggle("settings.display.pending-at-bottom", isOn: $userPreferences.pendingShownAtBottom)
|
2023-11-01 18:51:46 +01:00
|
|
|
Toggle("settings.display.pending-left", isOn: $userPreferences.pendingShownLeft)
|
2023-12-14 07:17:09 +01:00
|
|
|
Toggle("settings.display.show-reply-indentation", isOn: $userPreferences.showReplyIndentation)
|
|
|
|
if userPreferences.showReplyIndentation {
|
2023-12-17 07:33:55 +01:00
|
|
|
VStack {
|
|
|
|
Slider(value: .init(get: {
|
|
|
|
Double(userPreferences.maxReplyIndentation)
|
|
|
|
}, set: { newVal in
|
|
|
|
userPreferences.maxReplyIndentation = UInt(newVal)
|
2023-12-18 08:22:59 +01:00
|
|
|
}), in: 1 ... 20, step: 1)
|
2023-12-17 07:33:55 +01:00
|
|
|
Text("settings.display.max-reply-indentation-\(String(userPreferences.maxReplyIndentation))")
|
|
|
|
.font(.scaledBody)
|
|
|
|
}
|
2023-12-19 06:46:39 +01:00
|
|
|
.alignmentGuide(.listRowSeparatorLeading) { d in
|
|
|
|
d[.leading]
|
|
|
|
}
|
2023-12-14 07:17:09 +01:00
|
|
|
}
|
2023-12-17 07:57:20 +01:00
|
|
|
Toggle("settings.display.show-account-popover", isOn: $userPreferences.showAccountPopover)
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2023-03-03 08:29:45 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
2023-03-13 13:38:28 +01:00
|
|
|
|
2023-03-03 08:29:45 +01:00
|
|
|
@ViewBuilder
|
|
|
|
private var platformsSection: some View {
|
2023-09-19 09:18:20 +02:00
|
|
|
@Bindable var userPreferences = userPreferences
|
2023-02-09 06:22:34 +01:00
|
|
|
|
2023-03-03 08:29:45 +01:00
|
|
|
if UIDevice.current.userInterfaceIdiom == .pad {
|
2024-01-13 17:51:32 +01:00
|
|
|
Section("settings.display.section.platform") {
|
2023-03-03 08:29:45 +01:00
|
|
|
Toggle("settings.display.show-ipad-column", isOn: $userPreferences.showiPadSecondaryColumn)
|
2023-01-06 17:14:34 +01:00
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2023-01-06 17:14:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2023-01-06 17:14:34 +01:00
|
|
|
}
|
2023-03-03 08:29:45 +01:00
|
|
|
}
|
2023-03-13 13:38:28 +01:00
|
|
|
|
2023-03-03 08:29:45 +01:00
|
|
|
private var resetSection: some View {
|
|
|
|
Section {
|
|
|
|
Button {
|
2024-01-13 08:48:29 +01:00
|
|
|
theme.restoreDefault()
|
2023-03-03 08:29:45 +01:00
|
|
|
} label: {
|
|
|
|
Text("settings.display.restore")
|
|
|
|
}
|
|
|
|
}
|
2023-12-19 09:51:20 +01:00
|
|
|
#if !os(visionOS)
|
2023-03-03 08:29:45 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-12-19 09:51:20 +01:00
|
|
|
#endif
|
2023-01-06 17:14:34 +01:00
|
|
|
}
|
2023-02-09 06:22:34 +01:00
|
|
|
|
2023-01-06 17:14:34 +01:00
|
|
|
private var themeSelectorButton: some View {
|
|
|
|
NavigationLink(destination: ThemePreviewView()) {
|
|
|
|
HStack {
|
2023-01-19 18:14:08 +01:00
|
|
|
Text("settings.display.section.theme")
|
2023-01-06 17:14:34 +01:00
|
|
|
Spacer()
|
|
|
|
Text(theme.selectedSet.rawValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|