forked from shadowfacts/Tusker
Add preference to never blur attachments
This commit is contained in:
parent
00e8dd6345
commit
ffb5c76f7c
|
@ -52,7 +52,11 @@ class Preferences: Codable, ObservableObject {
|
||||||
self.mentionReblogger = try container.decode(Bool.self, forKey: .mentionReblogger)
|
self.mentionReblogger = try container.decode(Bool.self, forKey: .mentionReblogger)
|
||||||
self.useTwitterKeyboard = try container.decodeIfPresent(Bool.self, forKey: .useTwitterKeyboard) ?? false
|
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.blurMediaBehindContentWarning = try container.decodeIfPresent(Bool.self, forKey: .blurMediaBehindContentWarning) ?? true
|
||||||
self.automaticallyPlayGifs = try container.decode(Bool.self, forKey: .automaticallyPlayGifs)
|
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(mentionReblogger, forKey: .mentionReblogger)
|
||||||
try container.encode(useTwitterKeyboard, forKey: .useTwitterKeyboard)
|
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(blurMediaBehindContentWarning, forKey: .blurMediaBehindContentWarning)
|
||||||
try container.encode(automaticallyPlayGifs, forKey: .automaticallyPlayGifs)
|
try container.encode(automaticallyPlayGifs, forKey: .automaticallyPlayGifs)
|
||||||
|
|
||||||
|
@ -140,10 +144,12 @@ class Preferences: Codable, ObservableObject {
|
||||||
@Published var useTwitterKeyboard = false
|
@Published var useTwitterKeyboard = false
|
||||||
|
|
||||||
// MARK: Media
|
// MARK: Media
|
||||||
@Published var blurAllMedia = false {
|
@Published var attachmentBlurMode = AttachmentBlurMode.useStatusSetting {
|
||||||
didSet {
|
didSet {
|
||||||
if blurAllMedia {
|
if attachmentBlurMode == .always {
|
||||||
blurMediaBehindContentWarning = true
|
blurMediaBehindContentWarning = true
|
||||||
|
} else if attachmentBlurMode == .never {
|
||||||
|
blurMediaBehindContentWarning = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +197,8 @@ class Preferences: Codable, ObservableObject {
|
||||||
case mentionReblogger
|
case mentionReblogger
|
||||||
case useTwitterKeyboard
|
case useTwitterKeyboard
|
||||||
|
|
||||||
case blurAllMedia
|
case blurAllMedia // only used for migration
|
||||||
|
case attachmentBlurMode
|
||||||
case blurMediaBehindContentWarning
|
case blurMediaBehindContentWarning
|
||||||
case automaticallyPlayGifs
|
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 {}
|
extension UIUserInterfaceStyle: Codable {}
|
||||||
|
|
|
@ -21,14 +21,18 @@ struct MediaPrefsView: View {
|
||||||
|
|
||||||
var viewingSection: some View {
|
var viewingSection: some View {
|
||||||
Section(header: Text("Viewing")) {
|
Section(header: Text("Viewing")) {
|
||||||
Toggle(isOn: $preferences.blurAllMedia) {
|
Picker(selection: $preferences.attachmentBlurMode) {
|
||||||
Text("Blur All Media")
|
ForEach(Preferences.AttachmentBlurMode.allCases, id: \.self) { mode in
|
||||||
|
Text(mode.displayName).tag(mode)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Text("Blur Media")
|
||||||
}
|
}
|
||||||
|
|
||||||
Toggle(isOn: $preferences.blurMediaBehindContentWarning) {
|
Toggle(isOn: $preferences.blurMediaBehindContentWarning) {
|
||||||
Text("Blur Media Behind Content Warning")
|
Text("Blur Media Behind Content Warning")
|
||||||
}
|
}
|
||||||
.disabled(preferences.blurAllMedia)
|
.disabled(preferences.attachmentBlurMode != .useStatusSetting)
|
||||||
|
|
||||||
Toggle(isOn: $preferences.automaticallyPlayGifs) {
|
Toggle(isOn: $preferences.automaticallyPlayGifs) {
|
||||||
Text("Automatically Play GIFs")
|
Text("Automatically Play GIFs")
|
||||||
|
|
|
@ -231,16 +231,17 @@ class BaseStatusTableViewCell: UITableViewCell {
|
||||||
|
|
||||||
func updateUIForPreferences(account: AccountMO, status: StatusMO) {
|
func updateUIForPreferences(account: AccountMO, status: StatusMO) {
|
||||||
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
|
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
|
||||||
if Preferences.shared.blurAllMedia {
|
switch Preferences.shared.attachmentBlurMode {
|
||||||
attachmentsView.contentHidden = true
|
case .never:
|
||||||
} else if status.sensitive {
|
|
||||||
if !Preferences.shared.blurMediaBehindContentWarning && !status.spoilerText.isEmpty {
|
|
||||||
attachmentsView.contentHidden = false
|
attachmentsView.contentHidden = false
|
||||||
} else {
|
case .always:
|
||||||
attachmentsView.contentHidden = true
|
attachmentsView.contentHidden = true
|
||||||
|
default:
|
||||||
|
if status.sensitive {
|
||||||
|
attachmentsView.contentHidden = status.spoilerText.isEmpty || Preferences.shared.blurMediaBehindContentWarning
|
||||||
|
} else {
|
||||||
|
attachmentsView.contentHidden = false
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
attachmentsView.contentHidden = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStatusIconsForPreferences(status)
|
updateStatusIconsForPreferences(status)
|
||||||
|
|
|
@ -148,16 +148,17 @@ extension StatusCollectionViewCell {
|
||||||
|
|
||||||
func baseUpdateUIForPreferences(status: StatusMO) {
|
func baseUpdateUIForPreferences(status: StatusMO) {
|
||||||
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadiusFraction * Self.avatarImageViewSize
|
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadiusFraction * Self.avatarImageViewSize
|
||||||
if Preferences.shared.blurAllMedia {
|
switch Preferences.shared.attachmentBlurMode {
|
||||||
contentContainer.attachmentsView.contentHidden = true
|
case .never:
|
||||||
} else if status.sensitive {
|
|
||||||
if !Preferences.shared.blurMediaBehindContentWarning && !status.spoilerText.isEmpty {
|
|
||||||
contentContainer.attachmentsView.contentHidden = false
|
contentContainer.attachmentsView.contentHidden = false
|
||||||
} else {
|
case .always:
|
||||||
contentContainer.attachmentsView.contentHidden = true
|
contentContainer.attachmentsView.contentHidden = true
|
||||||
|
default:
|
||||||
|
if status.sensitive {
|
||||||
|
contentContainer.attachmentsView.contentHidden = status.spoilerText.isEmpty || Preferences.shared.blurMediaBehindContentWarning
|
||||||
|
} else {
|
||||||
|
contentContainer.attachmentsView.contentHidden = false
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
contentContainer.attachmentsView.contentHidden = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let reblogButtonImage: UIImage
|
let reblogButtonImage: UIImage
|
||||||
|
|
Loading…
Reference in New Issue