diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 11984588..1f68f7b5 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -52,6 +52,7 @@ class Preferences: Codable, ObservableObject { self.mentionReblogger = try container.decode(Bool.self, forKey: .mentionReblogger) self.blurAllMedia = try container.decode(Bool.self, forKey: .blurAllMedia) + self.blurMediaBehindContentWarning = try container.decodeIfPresent(Bool.self, forKey: .blurMediaBehindContentWarning) ?? true self.automaticallyPlayGifs = try container.decode(Bool.self, forKey: .automaticallyPlayGifs) self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps) @@ -92,6 +93,7 @@ class Preferences: Codable, ObservableObject { try container.encode(mentionReblogger, forKey: .mentionReblogger) try container.encode(blurAllMedia, forKey: .blurAllMedia) + try container.encode(blurMediaBehindContentWarning, forKey: .blurMediaBehindContentWarning) try container.encode(automaticallyPlayGifs, forKey: .automaticallyPlayGifs) try container.encode(openLinksInApps, forKey: .openLinksInApps) @@ -131,7 +133,14 @@ class Preferences: Codable, ObservableObject { @Published var mentionReblogger = false // MARK: Media - @Published var blurAllMedia = false + @Published var blurAllMedia = false { + didSet { + if blurAllMedia { + blurMediaBehindContentWarning = true + } + } + } + @Published var blurMediaBehindContentWarning = true @Published var automaticallyPlayGifs = true // MARK: Behavior @@ -174,6 +183,7 @@ class Preferences: Codable, ObservableObject { case mentionReblogger case blurAllMedia + case blurMediaBehindContentWarning case automaticallyPlayGifs case openLinksInApps diff --git a/Tusker/Screens/Preferences/MediaPrefsView.swift b/Tusker/Screens/Preferences/MediaPrefsView.swift index fc1abae3..3a886bab 100644 --- a/Tusker/Screens/Preferences/MediaPrefsView.swift +++ b/Tusker/Screens/Preferences/MediaPrefsView.swift @@ -24,6 +24,12 @@ struct MediaPrefsView: View { Toggle(isOn: $preferences.blurAllMedia) { Text("Blur All Media") } + + Toggle(isOn: $preferences.blurMediaBehindContentWarning) { + Text("Blur Media Behind Content Warning") + } + .disabled(preferences.blurAllMedia) + Toggle(isOn: $preferences.automaticallyPlayGifs) { Text("Automatically Play GIFs") } diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index b313d46e..8123aacd 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -236,27 +236,9 @@ class AttachmentsContainerView: UIView { // Make sure accessibilityElements is set every time the UI is updated, otherwise it holds // on to strong references to the old set of attachment views self.accessibilityElements = accessibilityElements - - contentHidden = Preferences.shared.blurAllMedia || status.sensitive } private func createAttachmentView(index: Int, hSize: RelativeSize, vSize: RelativeSize) -> AttachmentView { - let width: CGFloat - switch hSize { - case .full: - width = bounds.width - case .half: - width = (bounds.width - 4) / 2 - } - let height: CGFloat - switch vSize { - case .full: - height = bounds.height - case .half: - height = (bounds.height - 4) / 2 - } - let size = CGSize(width: width, height: height) - let attachmentView = AttachmentView(attachment: attachments[index], index: index) attachmentView.delegate = delegate attachmentView.translatesAutoresizingMaskIntoConstraints = false diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 517835d8..3e9122d1 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -231,7 +231,17 @@ class BaseStatusTableViewCell: UITableViewCell { func updateUIForPreferences(account: AccountMO, status: StatusMO) { avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView) - attachmentsView.contentHidden = Preferences.shared.blurAllMedia || status.sensitive + 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 { + attachmentsView.contentHidden = false + } updateStatusIconsForPreferences(status) diff --git a/Tusker/Views/Status/StatusCollectionViewCell.swift b/Tusker/Views/Status/StatusCollectionViewCell.swift index 5fa0c579..6e46875b 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -147,7 +147,17 @@ extension StatusCollectionViewCell { func baseUpdateUIForPreferences(status: StatusMO) { avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadiusFraction * Self.avatarImageViewSize - contentContainer.attachmentsView.contentHidden = Preferences.shared.blurAllMedia || status.sensitive + 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 { + contentContainer.attachmentsView.contentHidden = false + } let reblogButtonImage: UIImage if Preferences.shared.alwaysShowStatusVisibilityIcon || reblogEnabled(status: status) {