parent
1992a4c60b
commit
9e76879ce6
|
@ -65,6 +65,7 @@ class Preferences: Codable, ObservableObject {
|
|||
self.blurMediaBehindContentWarning = try container.decodeIfPresent(Bool.self, forKey: .blurMediaBehindContentWarning) ?? true
|
||||
self.automaticallyPlayGifs = try container.decode(Bool.self, forKey: .automaticallyPlayGifs)
|
||||
self.showUncroppedMediaInline = try container.decodeIfPresent(Bool.self, forKey: .showUncroppedMediaInline) ?? true
|
||||
self.showAttachmentBadges = try container.decodeIfPresent(Bool.self, forKey: .showAttachmentBadges) ?? true
|
||||
|
||||
self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps)
|
||||
self.useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari)
|
||||
|
@ -116,6 +117,7 @@ class Preferences: Codable, ObservableObject {
|
|||
try container.encode(blurMediaBehindContentWarning, forKey: .blurMediaBehindContentWarning)
|
||||
try container.encode(automaticallyPlayGifs, forKey: .automaticallyPlayGifs)
|
||||
try container.encode(showUncroppedMediaInline, forKey: .showUncroppedMediaInline)
|
||||
try container.encode(showAttachmentBadges, forKey: .showAttachmentBadges)
|
||||
|
||||
try container.encode(openLinksInApps, forKey: .openLinksInApps)
|
||||
try container.encode(useInAppSafari, forKey: .useInAppSafari)
|
||||
|
@ -175,6 +177,7 @@ class Preferences: Codable, ObservableObject {
|
|||
@Published var blurMediaBehindContentWarning = true
|
||||
@Published var automaticallyPlayGifs = true
|
||||
@Published var showUncroppedMediaInline = true
|
||||
@Published var showAttachmentBadges = true
|
||||
|
||||
// MARK: Behavior
|
||||
@Published var openLinksInApps = true
|
||||
|
@ -229,6 +232,7 @@ class Preferences: Codable, ObservableObject {
|
|||
case blurMediaBehindContentWarning
|
||||
case automaticallyPlayGifs
|
||||
case showUncroppedMediaInline
|
||||
case showAttachmentBadges
|
||||
|
||||
case openLinksInApps
|
||||
case useInAppSafari
|
||||
|
|
|
@ -42,6 +42,10 @@ struct MediaPrefsView: View {
|
|||
Toggle(isOn: $preferences.showUncroppedMediaInline) {
|
||||
Text("Show Uncropped Media Inline")
|
||||
}
|
||||
|
||||
Toggle(isOn: $preferences.showAttachmentBadges) {
|
||||
Text("Show GIF/ALT Badges")
|
||||
}
|
||||
}
|
||||
.appGroupedListRowBackground()
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ class AttachmentView: GIFImageView {
|
|||
|
||||
var playImageView: UIImageView?
|
||||
var gifvView: GifvAttachmentView?
|
||||
private var badgeContainer: UIStackView?
|
||||
|
||||
var attachment: Attachment!
|
||||
var index: Int!
|
||||
|
@ -77,6 +78,10 @@ class AttachmentView: GIFImageView {
|
|||
self.displayImage()
|
||||
}
|
||||
}
|
||||
|
||||
if getBadges().isEmpty != Preferences.shared.showAttachmentBadges {
|
||||
createBadgesView(getBadges())
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func gifPlaybackModeChanged() {
|
||||
|
@ -127,14 +132,7 @@ class AttachmentView: GIFImageView {
|
|||
}
|
||||
}
|
||||
|
||||
var badges: Badges = []
|
||||
if attachment.description?.isEmpty == false {
|
||||
badges.formUnion(.alt)
|
||||
}
|
||||
if attachment.kind == .gifv || attachment.url.pathExtension == "gif" {
|
||||
badges.formUnion(.gif)
|
||||
}
|
||||
createBadgesView(badges)
|
||||
createBadgesView(getBadges())
|
||||
|
||||
switch attachment.kind {
|
||||
case .image:
|
||||
|
@ -150,6 +148,20 @@ class AttachmentView: GIFImageView {
|
|||
}
|
||||
}
|
||||
|
||||
private func getBadges() -> Badges {
|
||||
guard Preferences.shared.showAttachmentBadges else {
|
||||
return []
|
||||
}
|
||||
var badges: Badges = []
|
||||
if attachment.description?.isEmpty == false {
|
||||
badges.formUnion(.alt)
|
||||
}
|
||||
if attachment.kind == .gifv || attachment.url.pathExtension == "gif" {
|
||||
badges.formUnion(.gif)
|
||||
}
|
||||
return badges
|
||||
}
|
||||
|
||||
var attachmentAspectRatio: CGFloat? {
|
||||
if let meta = self.attachment.meta {
|
||||
if let width = meta.width, let height = meta.height {
|
||||
|
@ -313,10 +325,13 @@ class AttachmentView: GIFImageView {
|
|||
|
||||
private func createBadgesView(_ badges: Badges) {
|
||||
guard !badges.isEmpty else {
|
||||
badgeContainer?.removeFromSuperview()
|
||||
badgeContainer = nil
|
||||
return
|
||||
}
|
||||
|
||||
let stack = UIStackView()
|
||||
self.badgeContainer = stack
|
||||
stack.axis = .horizontal
|
||||
stack.spacing = 2
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
|
Loading…
Reference in New Issue