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