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-01-06 17:14:34 +01:00
|
|
|
import Status
|
2023-01-17 11:36:01 +01:00
|
|
|
import SwiftUI
|
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-08 19:09:24 +01:00
|
|
|
|
2023-01-22 16:59:56 +01:00
|
|
|
@Environment(\.colorScheme) private var colorScheme
|
2023-01-06 17:14:34 +01:00
|
|
|
@EnvironmentObject private var theme: Theme
|
2023-01-17 21:08:05 +01:00
|
|
|
@EnvironmentObject private var userPreferences: UserPreferences
|
2023-02-08 19:09:24 +01:00
|
|
|
|
2023-01-30 07:27:06 +01:00
|
|
|
@State private var isFontSelectorPresented = false
|
2023-02-08 19:09:24 +01:00
|
|
|
|
|
|
|
private var previewStatusViewModel = StatusRowViewModel(status: Status.placeholder(parseMarkdown: true))
|
|
|
|
|
2023-01-06 17:14:34 +01:00
|
|
|
var body: some View {
|
|
|
|
Form {
|
2023-02-08 19:09:24 +01:00
|
|
|
Section("settings.display.example-toot") {
|
|
|
|
StatusRowView(viewModel: previewStatusViewModel)
|
|
|
|
.allowsHitTesting(false)
|
|
|
|
}
|
|
|
|
|
2023-01-26 18:27:16 +01:00
|
|
|
Section {
|
2023-01-20 21:58:57 +01:00
|
|
|
Toggle("settings.display.theme.systemColor", isOn: $theme.followSystemColorScheme)
|
2023-01-06 17:14:34 +01:00
|
|
|
themeSelectorButton
|
2023-01-26 18:27:16 +01:00
|
|
|
Group {
|
|
|
|
ColorPicker("settings.display.theme.tint", selection: $theme.tintColor)
|
|
|
|
ColorPicker("settings.display.theme.background", selection: $theme.primaryBackgroundColor)
|
|
|
|
ColorPicker("settings.display.theme.secondary-background", selection: $theme.secondaryBackgroundColor)
|
|
|
|
}
|
|
|
|
.disabled(theme.followSystemColorScheme)
|
|
|
|
.opacity(theme.followSystemColorScheme ? 0.5 : 1.0)
|
|
|
|
} header: {
|
|
|
|
Text("settings.display.section.theme")
|
|
|
|
} footer: {
|
|
|
|
if theme.followSystemColorScheme {
|
|
|
|
Text("settings.display.section.theme.footer")
|
|
|
|
}
|
2023-01-06 17:14:34 +01:00
|
|
|
}
|
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-02-08 19:09:24 +01:00
|
|
|
|
2023-01-19 18:14:08 +01:00
|
|
|
Section("settings.display.section.display") {
|
2023-02-06 18:15:08 +01:00
|
|
|
Picker("settings.display.font", selection: .init(get: { () -> FontState in
|
|
|
|
if userPreferences.chosenFont?.fontName == "OpenDyslexic-Regular" {
|
|
|
|
return FontState.openDyslexic
|
|
|
|
} else if userPreferences.chosenFont?.fontName == "AtkinsonHyperlegible-Regular" {
|
|
|
|
return FontState.hyperLegible
|
|
|
|
}
|
|
|
|
return userPreferences.chosenFontData != nil ? FontState.custom : FontState.system
|
2023-01-30 07:27:06 +01:00
|
|
|
}, set: { newValue in
|
|
|
|
switch newValue {
|
|
|
|
case .system:
|
|
|
|
userPreferences.chosenFont = nil
|
2023-02-06 18:15:08 +01:00
|
|
|
case .openDyslexic:
|
|
|
|
userPreferences.chosenFont = UIFont(name: "OpenDyslexic", size: 1)
|
|
|
|
case .hyperLegible:
|
|
|
|
userPreferences.chosenFont = UIFont(name: "Atkinson Hyperlegible", size: 1)
|
2023-01-30 07:27:06 +01:00
|
|
|
case .custom:
|
|
|
|
isFontSelectorPresented = true
|
2023-01-30 07:25:55 +01:00
|
|
|
}
|
2023-01-30 07:27:06 +01:00
|
|
|
})) {
|
|
|
|
ForEach(FontState.allCases, id: \.rawValue) { fontState in
|
|
|
|
Text(fontState.title).tag(fontState)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationDestination(isPresented: $isFontSelectorPresented, destination: { FontPicker() })
|
2023-01-19 18:14:08 +01:00
|
|
|
Picker("settings.display.avatar.position", selection: $theme.avatarPosition) {
|
2023-01-06 17:14:34 +01:00
|
|
|
ForEach(Theme.AvatarPosition.allCases, id: \.rawValue) { position in
|
|
|
|
Text(position.description).tag(position)
|
|
|
|
}
|
|
|
|
}
|
2023-01-19 18:14:08 +01:00
|
|
|
Picker("settings.display.avatar.shape", selection: $theme.avatarShape) {
|
2023-01-06 17:14:34 +01:00
|
|
|
ForEach(Theme.AvatarShape.allCases, id: \.rawValue) { shape in
|
|
|
|
Text(shape.description).tag(shape)
|
|
|
|
}
|
|
|
|
}
|
2023-01-19 18:14:08 +01:00
|
|
|
Picker("settings.display.status.action-buttons", selection: $theme.statusActionsDisplay) {
|
2023-01-06 17:14:34 +01:00
|
|
|
ForEach(Theme.StatusActionsDisplay.allCases, id: \.rawValue) { buttonStyle in
|
|
|
|
Text(buttonStyle.description).tag(buttonStyle)
|
|
|
|
}
|
|
|
|
}
|
2023-02-08 19:09:24 +01:00
|
|
|
|
2023-01-19 18:14:08 +01:00
|
|
|
Picker("settings.display.status.media-style", selection: $theme.statusDisplayStyle) {
|
2023-01-07 17:44:25 +01:00
|
|
|
ForEach(Theme.StatusDisplayStyle.allCases, id: \.rawValue) { buttonStyle in
|
|
|
|
Text(buttonStyle.description).tag(buttonStyle)
|
|
|
|
}
|
|
|
|
}
|
2023-01-31 12:16:11 +01:00
|
|
|
VStack {
|
|
|
|
Slider(value: $userPreferences.fontSizeScale, in: 0.5 ... 1.5, step: 0.1)
|
2023-02-01 18:53:43 +01:00
|
|
|
Text("settings.display.font.scaling-\(String(format: "%.1f", userPreferences.fontSizeScale))")
|
2023-01-31 12:16:11 +01:00
|
|
|
.font(.scaledBody)
|
2023-01-17 21:08:05 +01:00
|
|
|
}
|
2023-02-06 18:53:37 +01:00
|
|
|
.alignmentGuide(.listRowSeparatorLeading) { d in
|
|
|
|
d[.leading]
|
|
|
|
}
|
2023-01-22 09:15:01 +01:00
|
|
|
Toggle("settings.display.translate-button", isOn: $userPreferences.showTranslateButton)
|
2023-01-06 17:14:34 +01:00
|
|
|
}
|
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-02-06 18:53:37 +01:00
|
|
|
|
|
|
|
if UIDevice.current.userInterfaceIdiom == .pad {
|
|
|
|
Section("settings.display.section.ipad") {
|
|
|
|
Toggle("settings.display.show-ipad-column", isOn: $userPreferences.showiPadSecondaryColumn)
|
|
|
|
}
|
|
|
|
}
|
2023-02-08 19:09:24 +01:00
|
|
|
|
2023-01-06 17:14:34 +01:00
|
|
|
Section {
|
|
|
|
Button {
|
2023-01-22 16:59:56 +01:00
|
|
|
theme.followSystemColorScheme = true
|
|
|
|
theme.selectedSet = colorScheme == .dark ? .iceCubeDark : .iceCubeLight
|
2023-01-06 17:14:34 +01:00
|
|
|
theme.avatarShape = .rounded
|
|
|
|
theme.avatarPosition = .top
|
|
|
|
theme.statusActionsDisplay = .full
|
|
|
|
} label: {
|
2023-01-19 18:14:08 +01:00
|
|
|
Text("settings.display.restore")
|
2023-01-06 17:14:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
|
|
|
}
|
2023-01-19 18:14:08 +01:00
|
|
|
.navigationTitle("settings.display.navigation-title")
|
2023-01-06 17:14:34 +01:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
|
|
|
}
|
2023-02-08 19:09:24 +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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|