2020-08-07 03:41:59 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
2021-01-29 06:45:15 +01:00
|
|
|
import Mastodon
|
2020-08-07 03:41:59 +02:00
|
|
|
import SwiftUI
|
2020-09-01 09:33:49 +02:00
|
|
|
import ViewModels
|
2020-08-07 03:41:59 +02:00
|
|
|
|
2020-08-07 12:59:48 +02:00
|
|
|
struct PreferencesView: View {
|
|
|
|
@StateObject var viewModel: PreferencesViewModel
|
2021-01-29 06:45:15 +01:00
|
|
|
@StateObject var identityContext: IdentityContext
|
|
|
|
@Environment(\.accessibilityReduceMotion) var accessibilityReduceMotion
|
|
|
|
|
|
|
|
init(viewModel: PreferencesViewModel) {
|
|
|
|
_viewModel = StateObject(wrappedValue: viewModel)
|
|
|
|
_identityContext = StateObject(wrappedValue: viewModel.identityContext)
|
|
|
|
}
|
2020-08-07 12:59:48 +02:00
|
|
|
|
2020-08-07 03:41:59 +02:00
|
|
|
var body: some View {
|
2020-08-07 12:14:14 +02:00
|
|
|
Form {
|
2021-01-29 06:45:15 +01:00
|
|
|
Section(header: Text(viewModel.identityContext.identity.handle)) {
|
|
|
|
if viewModel.identityContext.identity.authenticated
|
|
|
|
&& !viewModel.identityContext.identity.pending {
|
|
|
|
NavigationLink("preferences.filters",
|
|
|
|
destination: FiltersView(
|
2021-01-26 01:45:18 +01:00
|
|
|
viewModel: .init(identityContext: viewModel.identityContext)))
|
2021-01-29 06:45:15 +01:00
|
|
|
if viewModel.shouldShowNotificationTypePreferences {
|
|
|
|
NavigationLink("preferences.notification-types",
|
|
|
|
destination: NotificationTypesPreferencesView(
|
|
|
|
viewModel: .init(identityContext: viewModel.identityContext)))
|
|
|
|
}
|
|
|
|
NavigationLink("preferences.muted-users",
|
|
|
|
destination: TableView(viewModelClosure: viewModel.mutedUsersViewModel)
|
|
|
|
.navigationTitle(Text("preferences.muted-users")))
|
|
|
|
NavigationLink("preferences.blocked-users",
|
|
|
|
destination: TableView(viewModelClosure: viewModel.blockedUsersViewModel)
|
|
|
|
.navigationTitle(Text("preferences.blocked-users")))
|
|
|
|
NavigationLink("preferences.blocked-domains",
|
|
|
|
destination: DomainBlocksView(viewModel: viewModel.domainBlocksViewModel()))
|
|
|
|
Toggle("preferences.use-preferences-from-server",
|
|
|
|
isOn: $viewModel.preferences.useServerPostingReadingPreferences)
|
|
|
|
Group {
|
|
|
|
Picker("preferences.posting-default-visiblility",
|
|
|
|
selection: $viewModel.preferences.postingDefaultVisibility) {
|
|
|
|
Text("status.visibility.public").tag(Status.Visibility.public)
|
|
|
|
Text("status.visibility.unlisted").tag(Status.Visibility.unlisted)
|
|
|
|
Text("status.visibility.private").tag(Status.Visibility.private)
|
|
|
|
}
|
|
|
|
Toggle("preferences.posting-default-sensitive",
|
|
|
|
isOn: $viewModel.preferences.postingDefaultSensitive)
|
|
|
|
}
|
|
|
|
.disabled(viewModel.preferences.useServerPostingReadingPreferences)
|
|
|
|
}
|
|
|
|
Group {
|
|
|
|
Picker("preferences.reading-expand-media",
|
|
|
|
selection: $viewModel.preferences.readingExpandMedia) {
|
|
|
|
Text("preferences.expand-media.default").tag(Preferences.ExpandMedia.default)
|
|
|
|
Text("preferences.expand-media.show-all").tag(Preferences.ExpandMedia.showAll)
|
|
|
|
Text("preferences.expand-media.hide-all").tag(Preferences.ExpandMedia.hideAll)
|
|
|
|
}
|
|
|
|
Toggle("preferences.reading-expand-spoilers",
|
|
|
|
isOn: $viewModel.preferences.readingExpandSpoilers)
|
2020-08-16 22:30:28 +02:00
|
|
|
}
|
2021-01-31 17:10:34 +01:00
|
|
|
.disabled(viewModel.preferences.useServerPostingReadingPreferences
|
|
|
|
&& viewModel.identityContext.identity.authenticated)
|
2020-08-07 12:14:14 +02:00
|
|
|
}
|
2020-10-15 09:44:01 +02:00
|
|
|
Section(header: Text("preferences.app")) {
|
2021-01-31 02:43:48 +01:00
|
|
|
Picker("preferences.status-word",
|
|
|
|
selection: $identityContext.appPreferences.statusWord) {
|
|
|
|
ForEach(AppPreferences.StatusWord.allCases) { option in
|
|
|
|
Text(option.localizedStringKey).tag(option)
|
|
|
|
}
|
|
|
|
}
|
2021-01-31 20:23:33 +01:00
|
|
|
Toggle("preferences.require-double-tap-to-reblog",
|
|
|
|
isOn: $identityContext.appPreferences.requireDoubleTapToReblog)
|
|
|
|
Toggle("preferences.require-double-tap-to-favorite",
|
|
|
|
isOn: $identityContext.appPreferences.requireDoubleTapToFavorite)
|
2021-01-29 06:45:15 +01:00
|
|
|
if accessibilityReduceMotion {
|
|
|
|
Toggle("preferences.media.use-system-reduce-motion",
|
|
|
|
isOn: $identityContext.appPreferences.useSystemReduceMotionForMedia)
|
|
|
|
}
|
|
|
|
Group {
|
|
|
|
Picker("preferences.media.autoplay.gifs",
|
|
|
|
selection: reduceMotion ? .constant(.never) : $identityContext.appPreferences.autoplayGIFs) {
|
|
|
|
ForEach(AppPreferences.Autoplay.allCases) { option in
|
|
|
|
Text(option.localizedStringKey).tag(option)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Picker("preferences.media.autoplay.videos",
|
|
|
|
selection: reduceMotion
|
|
|
|
? .constant(.never) : $identityContext.appPreferences.autoplayVideos) {
|
|
|
|
ForEach(AppPreferences.Autoplay.allCases) { option in
|
|
|
|
Text(option.localizedStringKey).tag(option)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Picker("preferences.media.avatars.animate",
|
|
|
|
selection: reduceMotion
|
|
|
|
? .constant(.never) : $identityContext.appPreferences.animateAvatars) {
|
|
|
|
ForEach(AppPreferences.AnimateAvatars.allCases) { option in
|
|
|
|
Text(option.localizedStringKey).tag(option)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Toggle("preferences.media.headers.animate",
|
|
|
|
isOn: reduceMotion ? .constant(false) : $identityContext.appPreferences.animateHeaders)
|
|
|
|
.disabled(reduceMotion)
|
|
|
|
}
|
|
|
|
.disabled(reduceMotion)
|
2021-01-29 07:50:58 +01:00
|
|
|
Toggle("preferences.show-reblog-and-favorite-counts",
|
|
|
|
isOn: $identityContext.appPreferences.showReblogAndFavoriteCounts)
|
2021-01-31 17:10:34 +01:00
|
|
|
if viewModel.identityContext.identity.authenticated
|
|
|
|
&& !viewModel.identityContext.identity.pending {
|
|
|
|
Picker("preferences.home-timeline-position-on-startup",
|
|
|
|
selection: $identityContext.appPreferences.homeTimelineBehavior) {
|
|
|
|
ForEach(AppPreferences.PositionBehavior.allCases) { option in
|
|
|
|
Text(option.localizedStringKey).tag(option)
|
|
|
|
}
|
2021-01-29 06:45:15 +01:00
|
|
|
}
|
2021-01-31 17:10:34 +01:00
|
|
|
Picker("preferences.notifications-position-on-startup",
|
|
|
|
selection: $identityContext.appPreferences.notificationsTabBehavior) {
|
|
|
|
ForEach(AppPreferences.PositionBehavior.allCases) { option in
|
|
|
|
Text(option.localizedStringKey).tag(option)
|
|
|
|
}
|
2021-01-29 06:45:15 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-15 09:44:01 +02:00
|
|
|
}
|
2020-08-07 12:14:14 +02:00
|
|
|
}
|
2020-08-07 12:59:48 +02:00
|
|
|
.navigationTitle("preferences")
|
2021-01-29 06:45:15 +01:00
|
|
|
.alertItem($viewModel.alertItem)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension PreferencesView {
|
|
|
|
var reduceMotion: Bool {
|
|
|
|
identityContext.appPreferences.shouldReduceMotion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 02:43:48 +01:00
|
|
|
extension AppPreferences.StatusWord {
|
|
|
|
var localizedStringKey: LocalizedStringKey {
|
|
|
|
switch self {
|
|
|
|
case .toot:
|
|
|
|
return "toot"
|
|
|
|
case .post:
|
|
|
|
return "post"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 06:45:15 +01:00
|
|
|
extension AppPreferences.AnimateAvatars {
|
|
|
|
var localizedStringKey: LocalizedStringKey {
|
|
|
|
switch self {
|
|
|
|
case .everywhere:
|
|
|
|
return "preferences.media.avatars.animate.everywhere"
|
|
|
|
case .profiles:
|
|
|
|
return "preferences.media.avatars.animate.profiles"
|
|
|
|
case .never:
|
|
|
|
return "preferences.media.avatars.animate.never"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension AppPreferences.Autoplay {
|
|
|
|
var localizedStringKey: LocalizedStringKey {
|
|
|
|
switch self {
|
|
|
|
case .always:
|
|
|
|
return "preferences.media.autoplay.always"
|
|
|
|
case .wifi:
|
|
|
|
return "preferences.media.autoplay.wifi"
|
|
|
|
case .never:
|
|
|
|
return "preferences.media.autoplay.never"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension AppPreferences.PositionBehavior {
|
|
|
|
var localizedStringKey: LocalizedStringKey {
|
|
|
|
switch self {
|
|
|
|
case .rememberPosition:
|
|
|
|
return "preferences.position.remember-position"
|
|
|
|
case .syncPosition:
|
|
|
|
return "preferences.position.sync-position"
|
|
|
|
case .newest:
|
|
|
|
return "preferences.position.newest"
|
|
|
|
}
|
2020-08-07 03:41:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:37:14 +02:00
|
|
|
#if DEBUG
|
2020-09-01 09:33:49 +02:00
|
|
|
import PreviewViewModels
|
|
|
|
|
2020-08-07 03:41:59 +02:00
|
|
|
struct PreferencesView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-01-26 01:06:35 +01:00
|
|
|
PreferencesView(viewModel: .init(identityContext: .preview))
|
2020-08-07 03:41:59 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-12 09:37:14 +02:00
|
|
|
#endif
|