metatext/Views/MediaPreferencesView.swift

97 lines
3.5 KiB
Swift
Raw Normal View History

2020-10-15 07:44:01 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import SwiftUI
import ViewModels
struct MediaPreferencesView: View {
@StateObject var viewModel: MediaPreferencesViewModel
@StateObject var identityContext: IdentityContext
2020-10-15 07:44:01 +00:00
@Environment(\.accessibilityReduceMotion) var accessibilityReduceMotion
init(viewModel: MediaPreferencesViewModel) {
_viewModel = StateObject(wrappedValue: viewModel)
_identityContext = StateObject(wrappedValue: viewModel.identityContext)
}
2020-10-15 07:44:01 +00:00
var body: some View {
Form {
if accessibilityReduceMotion {
Section {
Toggle("preferences.media.use-system-reduce-motion",
2021-01-26 00:06:35 +00:00
isOn: $identityContext.appPreferences.useSystemReduceMotionForMedia)
2020-10-15 07:44:01 +00:00
}
}
Section(header: Text("preferences.media.autoplay")) {
Picker("preferences.media.autoplay.gifs",
2021-01-26 00:06:35 +00:00
selection: reduceMotion ? .constant(.never) : $identityContext.appPreferences.autoplayGIFs) {
2020-10-15 07:44:01 +00:00
ForEach(AppPreferences.Autoplay.allCases) { option in
Text(option.localizedStringKey).tag(option)
}
}
Picker("preferences.media.autoplay.videos",
2021-01-26 00:06:35 +00:00
selection: reduceMotion ? .constant(.never) : $identityContext.appPreferences.autoplayVideos) {
2020-10-15 07:44:01 +00:00
ForEach(AppPreferences.Autoplay.allCases) { option in
Text(option.localizedStringKey).tag(option)
}
}
}
.disabled(reduceMotion)
Section(header: Text("preferences.media.avatars")) {
Picker("preferences.media.avatars.animate",
2021-01-26 00:06:35 +00:00
selection: reduceMotion ? .constant(.never) : $identityContext.appPreferences.animateAvatars) {
2020-10-15 07:44:01 +00:00
ForEach(AppPreferences.AnimateAvatars.allCases) { option in
Text(option.localizedStringKey).tag(option)
}
}
.disabled(reduceMotion)
}
Section(header: Text("preferences.media.headers")) {
Toggle("preferences.media.headers.animate",
2021-01-26 00:06:35 +00:00
isOn: reduceMotion ? .constant(false) : $identityContext.appPreferences.animateHeaders)
2020-10-15 07:44:01 +00:00
.disabled(reduceMotion)
}
}
.navigationTitle("preferences.media")
}
}
private extension MediaPreferencesView {
var reduceMotion: Bool {
2021-01-26 00:06:35 +00:00
identityContext.appPreferences.shouldReduceMotion
2020-10-15 07:44:01 +00: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"
}
}
}
#if DEBUG
struct MediaPreferencesView_Previews: PreviewProvider {
static var previews: some View {
2021-01-26 00:06:35 +00:00
MediaPreferencesView(viewModel: .init(identityContext: .preview))
2020-10-15 07:44:01 +00:00
}
}
#endif