forked from shadowfacts/Tusker
Add preference to disable gif animation in timelines
This commit is contained in:
parent
65d57df949
commit
1f56823a17
|
@ -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
|
||||
|
|
|
@ -60,6 +60,9 @@ struct BehaviorPrefsView: View {
|
|||
Toggle(isOn: $preferences.blurAllMedia) {
|
||||
Text("Blur All Media")
|
||||
}
|
||||
Toggle(isOn: $preferences.automaticallyPlayGifs) {
|
||||
Text("Automatically Play GIFs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue