From 333295367a0a903030efdaf50efc8f0fa7f25395 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 26 Jan 2023 17:18:27 -0500 Subject: [PATCH] Add preference to hide link preview cards Closes #329 --- Tusker/Preferences/Preferences.swift | 4 ++++ .../Preferences/AppearancePrefsView.swift | 3 +++ .../Status/StatusCollectionViewCell.swift | 20 ++++++++++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 0f7707fe..d857c78b 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -44,6 +44,7 @@ class Preferences: Codable, ObservableObject { self.showIsStatusReplyIcon = try container.decode(Bool.self, forKey: .showIsStatusReplyIcon) self.alwaysShowStatusVisibilityIcon = try container.decode(Bool.self, forKey: .alwaysShowStatusVisibilityIcon) self.hideActionsInTimeline = try container.decodeIfPresent(Bool.self, forKey: .hideActionsInTimeline) ?? false + self.showLinkPreviews = try container.decodeIfPresent(Bool.self, forKey: .showLinkPreviews) ?? true self.leadingStatusSwipeActions = try container.decodeIfPresent([StatusSwipeAction].self, forKey: .leadingStatusSwipeActions) ?? leadingStatusSwipeActions self.trailingStatusSwipeActions = try container.decodeIfPresent([StatusSwipeAction].self, forKey: .trailingStatusSwipeActions) ?? trailingStatusSwipeActions @@ -97,6 +98,7 @@ class Preferences: Codable, ObservableObject { try container.encode(showIsStatusReplyIcon, forKey: .showIsStatusReplyIcon) try container.encode(alwaysShowStatusVisibilityIcon, forKey: .alwaysShowStatusVisibilityIcon) try container.encode(hideActionsInTimeline, forKey: .hideActionsInTimeline) + try container.encode(showLinkPreviews, forKey: .showLinkPreviews) try container.encode(leadingStatusSwipeActions, forKey: .leadingStatusSwipeActions) try container.encode(trailingStatusSwipeActions, forKey: .trailingStatusSwipeActions) @@ -144,6 +146,7 @@ class Preferences: Codable, ObservableObject { @Published var showIsStatusReplyIcon = false @Published var alwaysShowStatusVisibilityIcon = false @Published var hideActionsInTimeline = false + @Published var showLinkPreviews = true @Published var leadingStatusSwipeActions: [StatusSwipeAction] = [.favorite, .reblog] @Published var trailingStatusSwipeActions: [StatusSwipeAction] = [.reply, .share] @@ -205,6 +208,7 @@ class Preferences: Codable, ObservableObject { case showIsStatusReplyIcon case alwaysShowStatusVisibilityIcon case hideActionsInTimeline + case showLinkPreviews case leadingStatusSwipeActions case trailingStatusSwipeActions diff --git a/Tusker/Screens/Preferences/AppearancePrefsView.swift b/Tusker/Screens/Preferences/AppearancePrefsView.swift index 53fdf872..b0780279 100644 --- a/Tusker/Screens/Preferences/AppearancePrefsView.swift +++ b/Tusker/Screens/Preferences/AppearancePrefsView.swift @@ -84,6 +84,9 @@ struct AppearancePrefsView : View { Toggle(isOn: $preferences.hideActionsInTimeline) { Text("Hide Actions on Timeline") } + Toggle(isOn: $preferences.showLinkPreviews) { + Text("Show Link Previews") + } NavigationLink("Leading Swipe Actions") { SwipeActionsPrefsView(selection: $preferences.leadingStatusSwipeActions) .edgesIgnoringSafeArea(.all) diff --git a/Tusker/Views/Status/StatusCollectionViewCell.swift b/Tusker/Views/Status/StatusCollectionViewCell.swift index 9a27d04a..4fb7483b 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -83,17 +83,21 @@ extension StatusCollectionViewCell { accountID = status.account.id updateAccountUI(account: status.account) - updateUIForPreferences(status: status) contentContainer.contentTextView.setTextFrom(status: status, precomputed: precomputedContent) contentContainer.contentTextView.navigationDelegate = delegate contentContainer.attachmentsView.delegate = self contentContainer.attachmentsView.updateUI(status: status) - contentContainer.cardView.updateUI(status: status) - contentContainer.cardView.isHidden = status.card == nil - contentContainer.cardView.navigationDelegate = delegate - contentContainer.cardView.actionProvider = delegate + if Preferences.shared.showLinkPreviews { + contentContainer.cardView.updateUI(status: status) + contentContainer.cardView.isHidden = status.card == nil + contentContainer.cardView.navigationDelegate = delegate + contentContainer.cardView.actionProvider = delegate + } else { + contentContainer.cardView.isHidden = true + } + updateUIForPreferences(status: status) updateStatusState(status: status) contentWarningLabel.text = status.spoilerText @@ -150,6 +154,12 @@ extension StatusCollectionViewCell { func baseUpdateUIForPreferences(status: StatusMO) { avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadiusFraction * Self.avatarImageViewSize + + let newCardHidden = !Preferences.shared.showLinkPreviews || status.card == nil + if contentContainer.cardView.isHidden != newCardHidden { + delegate?.statusCellNeedsReconfigure(self, animated: false, completion: nil) + } + switch Preferences.shared.attachmentBlurMode { case .never: contentContainer.attachmentsView.contentHidden = false