diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 6b784898..78407873 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -52,7 +52,11 @@ class Preferences: Codable, ObservableObject { self.mentionReblogger = try container.decode(Bool.self, forKey: .mentionReblogger) self.useTwitterKeyboard = try container.decodeIfPresent(Bool.self, forKey: .useTwitterKeyboard) ?? false - self.blurAllMedia = try container.decode(Bool.self, forKey: .blurAllMedia) + if let blurAllMedia = try? container.decodeIfPresent(Bool.self, forKey: .blurAllMedia) { + self.attachmentBlurMode = blurAllMedia ? .always : .useStatusSetting + } else { + self.attachmentBlurMode = try container.decode(AttachmentBlurMode.self, forKey: .attachmentBlurMode) + } self.blurMediaBehindContentWarning = try container.decodeIfPresent(Bool.self, forKey: .blurMediaBehindContentWarning) ?? true self.automaticallyPlayGifs = try container.decode(Bool.self, forKey: .automaticallyPlayGifs) @@ -95,7 +99,7 @@ class Preferences: Codable, ObservableObject { try container.encode(mentionReblogger, forKey: .mentionReblogger) try container.encode(useTwitterKeyboard, forKey: .useTwitterKeyboard) - try container.encode(blurAllMedia, forKey: .blurAllMedia) + try container.encode(attachmentBlurMode, forKey: .attachmentBlurMode) try container.encode(blurMediaBehindContentWarning, forKey: .blurMediaBehindContentWarning) try container.encode(automaticallyPlayGifs, forKey: .automaticallyPlayGifs) @@ -140,10 +144,12 @@ class Preferences: Codable, ObservableObject { @Published var useTwitterKeyboard = false // MARK: Media - @Published var blurAllMedia = false { + @Published var attachmentBlurMode = AttachmentBlurMode.useStatusSetting { didSet { - if blurAllMedia { + if attachmentBlurMode == .always { blurMediaBehindContentWarning = true + } else if attachmentBlurMode == .never { + blurMediaBehindContentWarning = false } } } @@ -191,7 +197,8 @@ class Preferences: Codable, ObservableObject { case mentionReblogger case useTwitterKeyboard - case blurAllMedia + case blurAllMedia // only used for migration + case attachmentBlurMode case blurMediaBehindContentWarning case automaticallyPlayGifs @@ -254,4 +261,23 @@ extension Preferences { } } +extension Preferences { + enum AttachmentBlurMode: Codable, Hashable, CaseIterable { + case useStatusSetting + case always + case never + + var displayName: String { + switch self { + case .useStatusSetting: + return "Default" + case .always: + return "Always" + case .never: + return "Never" + } + } + } +} + extension UIUserInterfaceStyle: Codable {} diff --git a/Tusker/Screens/Preferences/MediaPrefsView.swift b/Tusker/Screens/Preferences/MediaPrefsView.swift index 3a886bab..92b12301 100644 --- a/Tusker/Screens/Preferences/MediaPrefsView.swift +++ b/Tusker/Screens/Preferences/MediaPrefsView.swift @@ -21,14 +21,18 @@ struct MediaPrefsView: View { var viewingSection: some View { Section(header: Text("Viewing")) { - Toggle(isOn: $preferences.blurAllMedia) { - Text("Blur All Media") + Picker(selection: $preferences.attachmentBlurMode) { + ForEach(Preferences.AttachmentBlurMode.allCases, id: \.self) { mode in + Text(mode.displayName).tag(mode) + } + } label: { + Text("Blur Media") } Toggle(isOn: $preferences.blurMediaBehindContentWarning) { Text("Blur Media Behind Content Warning") } - .disabled(preferences.blurAllMedia) + .disabled(preferences.attachmentBlurMode != .useStatusSetting) Toggle(isOn: $preferences.automaticallyPlayGifs) { Text("Automatically Play GIFs") diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index d234f11d..15ef71dc 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -231,16 +231,17 @@ class BaseStatusTableViewCell: UITableViewCell { func updateUIForPreferences(account: AccountMO, status: StatusMO) { avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView) - if Preferences.shared.blurAllMedia { - attachmentsView.contentHidden = true - } else if status.sensitive { - if !Preferences.shared.blurMediaBehindContentWarning && !status.spoilerText.isEmpty { - attachmentsView.contentHidden = false - } else { - attachmentsView.contentHidden = true - } - } else { + switch Preferences.shared.attachmentBlurMode { + case .never: attachmentsView.contentHidden = false + case .always: + attachmentsView.contentHidden = true + default: + if status.sensitive { + attachmentsView.contentHidden = status.spoilerText.isEmpty || Preferences.shared.blurMediaBehindContentWarning + } else { + attachmentsView.contentHidden = false + } } updateStatusIconsForPreferences(status) diff --git a/Tusker/Views/Status/StatusCollectionViewCell.swift b/Tusker/Views/Status/StatusCollectionViewCell.swift index 66634ab2..9e48ab18 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -148,16 +148,17 @@ extension StatusCollectionViewCell { func baseUpdateUIForPreferences(status: StatusMO) { avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadiusFraction * Self.avatarImageViewSize - if Preferences.shared.blurAllMedia { - contentContainer.attachmentsView.contentHidden = true - } else if status.sensitive { - if !Preferences.shared.blurMediaBehindContentWarning && !status.spoilerText.isEmpty { - contentContainer.attachmentsView.contentHidden = false - } else { - contentContainer.attachmentsView.contentHidden = true - } - } else { + switch Preferences.shared.attachmentBlurMode { + case .never: contentContainer.attachmentsView.contentHidden = false + case .always: + contentContainer.attachmentsView.contentHidden = true + default: + if status.sensitive { + contentContainer.attachmentsView.contentHidden = status.spoilerText.isEmpty || Preferences.shared.blurMediaBehindContentWarning + } else { + contentContainer.attachmentsView.contentHidden = false + } } let reblogButtonImage: UIImage