2024-01-04 18:11:07 +01:00
|
|
|
//Made by Lumaa
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AppearenceView: View {
|
2024-01-04 22:19:35 +01:00
|
|
|
@ObservedObject private var userPreferences: UserPreferences = .defaultPreferences
|
|
|
|
@Environment(Navigator.self) private var navigator: Navigator
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
|
2024-01-04 18:11:07 +01:00
|
|
|
var body: some View {
|
2024-01-04 22:19:35 +01:00
|
|
|
List {
|
|
|
|
Picker(LocalizedStringKey("setting.appearence.displayed-name"), selection: $userPreferences.displayedName) {
|
|
|
|
ForEach(UserPreferences.DisplayedName.allCases, id: \.self) { displayCase in
|
|
|
|
switch (displayCase) {
|
|
|
|
case .username:
|
|
|
|
Text("setting.appearence.displayed-name.username")
|
|
|
|
.tag(UserPreferences.DisplayedName.username)
|
|
|
|
case .displayName:
|
|
|
|
Text("setting.appearence.displayed-name.display-name")
|
|
|
|
.tag(UserPreferences.DisplayedName.displayName)
|
|
|
|
case .both:
|
|
|
|
Text("setting.appearence.displayed-name.both")
|
|
|
|
.tag(UserPreferences.DisplayedName.both)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.pickerStyle(.inline)
|
|
|
|
.listRowThreaded()
|
|
|
|
|
|
|
|
Picker(LocalizedStringKey("setting.appearence.pfp-shape"), selection: $userPreferences.profilePictureShape) {
|
|
|
|
ForEach(UserPreferences.ProfilePictureShape.allCases, id: \.self) { displayCase in
|
|
|
|
switch (displayCase) {
|
|
|
|
case .circle:
|
|
|
|
Text("setting.appearence.pfp-shape.circle")
|
|
|
|
.tag(UserPreferences.ProfilePictureShape.circle)
|
|
|
|
case .rounded:
|
|
|
|
Text("setting.appearence.pfp-shape.rounded")
|
|
|
|
.tag(UserPreferences.ProfilePictureShape.rounded)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.pickerStyle(.inline)
|
|
|
|
.listRowThreaded()
|
|
|
|
|
|
|
|
if userPreferences.showExperimental {
|
|
|
|
Section(header: Text("experimental")) {
|
|
|
|
Toggle(LocalizedStringKey("setting.appearence.reply-symbols"), isOn: $userPreferences.experimental.replySymbol)
|
|
|
|
.listRowThreaded()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.listThreaded()
|
|
|
|
.navigationTitle("setting.appearence")
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
.navigationBarBackButtonHidden()
|
|
|
|
.onAppear {
|
|
|
|
do {
|
|
|
|
let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences
|
|
|
|
|
|
|
|
userPreferences.displayedName = oldPreferences.displayedName
|
|
|
|
userPreferences.profilePictureShape = oldPreferences.profilePictureShape
|
|
|
|
|
|
|
|
userPreferences.experimental.replySymbol = oldPreferences.experimental.replySymbol
|
|
|
|
} catch {
|
|
|
|
print(error)
|
|
|
|
dismiss()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
|
|
Button {
|
|
|
|
do {
|
|
|
|
let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences
|
|
|
|
|
|
|
|
userPreferences.displayedName = oldPreferences.displayedName
|
|
|
|
userPreferences.profilePictureShape = oldPreferences.profilePictureShape
|
|
|
|
|
|
|
|
userPreferences.experimental.replySymbol = oldPreferences.experimental.replySymbol
|
|
|
|
|
|
|
|
dismiss()
|
|
|
|
} catch {
|
|
|
|
print(error)
|
|
|
|
dismiss()
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Text("settings.cancel")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolbarItem(placement: .primaryAction) {
|
|
|
|
Button {
|
|
|
|
do {
|
|
|
|
try userPreferences.saveAsCurrent()
|
|
|
|
dismiss()
|
|
|
|
} catch {
|
|
|
|
print(error)
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Text("settings.done")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-04 18:11:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#Preview {
|
|
|
|
AppearenceView()
|
|
|
|
}
|