Add preference to disable gif animation in timelines

This commit is contained in:
Shadowfacts 2020-02-22 13:12:28 -05:00
parent 65d57df949
commit 1f56823a17
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 23 additions and 1 deletions

View File

@ -48,6 +48,7 @@ class Preferences: Codable, ObservableObject {
self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode)
self.mentionReblogger = try container.decode(Bool.self, forKey: .mentionReblogger)
self.blurAllMedia = try container.decode(Bool.self, forKey: .blurAllMedia)
self.automaticallyPlayGifs = try container.decode(Bool.self, forKey: .automaticallyPlayGifs)
self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps)
self.useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari)
self.inAppSafariAutomaticReaderMode = try container.decode(Bool.self, forKey: .inAppSafariAutomaticReaderMode)
@ -73,6 +74,7 @@ class Preferences: Codable, ObservableObject {
try container.encode(contentWarningCopyMode, forKey: .contentWarningCopyMode)
try container.encode(mentionReblogger, forKey: .mentionReblogger)
try container.encode(blurAllMedia, forKey: .blurAllMedia)
try container.encode(automaticallyPlayGifs, forKey: .automaticallyPlayGifs)
try container.encode(openLinksInApps, forKey: .openLinksInApps)
try container.encode(useInAppSafari, forKey: .useInAppSafari)
try container.encode(inAppSafariAutomaticReaderMode, forKey: .inAppSafariAutomaticReaderMode)
@ -97,6 +99,7 @@ class Preferences: Codable, ObservableObject {
@Published var contentWarningCopyMode = ContentWarningCopyMode.asIs
@Published var mentionReblogger = false
@Published var blurAllMedia = false
@Published var automaticallyPlayGifs = true
@Published var openLinksInApps = true
@Published var useInAppSafari = true
@Published var inAppSafariAutomaticReaderMode = false
@ -121,6 +124,7 @@ class Preferences: Codable, ObservableObject {
case contentWarningCopyMode
case mentionReblogger
case blurAllMedia
case automaticallyPlayGifs
case openLinksInApps
case useInAppSafari
case inAppSafariAutomaticReaderMode

View File

@ -60,6 +60,9 @@ struct BehaviorPrefsView: View {
Toggle(isOn: $preferences.blurAllMedia) {
Text("Blur All Media")
}
Toggle(isOn: $preferences.automaticallyPlayGifs) {
Text("Automatically Play GIFs")
}
}
}

View File

@ -54,6 +54,17 @@ class AttachmentView: UIImageView, GIFAnimatable {
isUserInteractionEnabled = true
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imagePressed)))
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
}
@objc func preferencesChanged() {
if let gifData = gifData {
if Preferences.shared.automaticallyPlayGifs && !isAnimatingGIF {
animate(withGIFData: gifData)
} else if !Preferences.shared.automaticallyPlayGifs && isAnimatingGIF {
stopAnimatingGIF()
}
}
}
func loadAttachment() {
@ -78,8 +89,12 @@ class AttachmentView: UIImageView, GIFAnimatable {
self.attachmentRequest = nil
DispatchQueue.main.async {
if self.attachment.url.pathExtension == "gif" {
self.animate(withGIFData: data)
self.gifData = data
if Preferences.shared.automaticallyPlayGifs {
self.animate(withGIFData: data)
} else {
self.image = UIImage(data: data)
}
} else {
self.image = UIImage(data: data)
}