From 66020b7847f1dca78f342a1b1097afd061b65b72 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 17 Jun 2020 18:00:13 -0400 Subject: [PATCH] Add preference for always showing status visiblity icon --- Tusker/Preferences/Preferences.swift | 4 ++ .../Preferences/AppearancePrefsView.swift | 3 ++ .../Status/BaseStatusTableViewCell.swift | 27 ++++++++--- .../Status/TimelineStatusTableViewCell.swift | 9 ++-- .../Status/TimelineStatusTableViewCell.xib | 47 ++++++++++--------- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index d6c515ab11..2680891806 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -42,6 +42,7 @@ class Preferences: Codable, ObservableObject { self.avatarStyle = try container.decode(AvatarStyle.self, forKey: .avatarStyle) self.hideCustomEmojiInUsernames = try container.decode(Bool.self, forKey: .hideCustomEmojiInUsernames) self.showIsStatusReplyIcon = try container.decode(Bool.self, forKey: .showIsStatusReplyIcon) + self.alwaysShowStatusVisibilityIcon = try container.decode(Bool.self, forKey: .alwaysShowStatusVisibilityIcon) self.defaultPostVisibility = try container.decode(Status.Visibility.self, forKey: .defaultPostVisibility) self.automaticallySaveDrafts = try container.decode(Bool.self, forKey: .automaticallySaveDrafts) @@ -71,6 +72,7 @@ class Preferences: Codable, ObservableObject { try container.encode(avatarStyle, forKey: .avatarStyle) try container.encode(hideCustomEmojiInUsernames, forKey: .hideCustomEmojiInUsernames) try container.encode(showIsStatusReplyIcon, forKey: .showIsStatusReplyIcon) + try container.encode(alwaysShowStatusVisibilityIcon, forKey: .alwaysShowStatusVisibilityIcon) try container.encode(defaultPostVisibility, forKey: .defaultPostVisibility) try container.encode(automaticallySaveDrafts, forKey: .automaticallySaveDrafts) @@ -98,6 +100,7 @@ class Preferences: Codable, ObservableObject { @Published var avatarStyle = AvatarStyle.roundRect @Published var hideCustomEmojiInUsernames = false @Published var showIsStatusReplyIcon = false + @Published var alwaysShowStatusVisibilityIcon = false // MARK: Composing @Published var defaultPostVisibility = Status.Visibility.public @@ -129,6 +132,7 @@ class Preferences: Codable, ObservableObject { case avatarStyle case hideCustomEmojiInUsernames case showIsStatusReplyIcon + case alwaysShowStatusVisibilityIcon case defaultPostVisibility case automaticallySaveDrafts diff --git a/Tusker/Screens/Preferences/AppearancePrefsView.swift b/Tusker/Screens/Preferences/AppearancePrefsView.swift index 272e460ed6..1c30c1e7e1 100644 --- a/Tusker/Screens/Preferences/AppearancePrefsView.swift +++ b/Tusker/Screens/Preferences/AppearancePrefsView.swift @@ -42,6 +42,9 @@ struct AppearancePrefsView : View { Toggle(isOn: $preferences.showIsStatusReplyIcon) { Text("Show Status Reply Icons") } + Toggle(isOn: $preferences.alwaysShowStatusVisibilityIcon) { + Text("Always Show Status Visibility Icons") + } } .listStyle(GroupedListStyle()) .navigationBarTitle(Text("Appearance")) diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 34c6154366..ca7d452092 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -128,9 +128,6 @@ class BaseStatusTableViewCell: UITableViewCell { updateUI(account: account) updateUIForPreferences(account: account) - visibilityImageView.image = UIImage(systemName: status.visibility.unfilledImageName) - visibilityImageView.accessibilityLabel = String(format: NSLocalizedString("Visibility: %@", comment: "status visibility indicator accessibility label"), status.visibility.displayName) - attachmentsView.updateUI(status: status) attachmentsView.isAccessibilityElement = status.attachments.count > 0 attachmentsView.accessibilityLabel = String(format: NSLocalizedString("%d attachments", comment: "status attachments count accessibility label"), status.attachments.count) @@ -154,8 +151,8 @@ class BaseStatusTableViewCell: UITableViewCell { reblogDisabled = status.visibility == .direct || (status.visibility == .private && status.account.id != mastodonController.account.id) } reblogButton.isEnabled = !reblogDisabled - let reblogButtonImage = reblogDisabled ? UIImage(systemName: status.visibility.imageName) : UIImage(systemName: "repeat") - reblogButton.setImage(reblogButtonImage, for: .normal) + + updateStatusIconsForPreferences(status) if state.unknown { collapsible = !status.spoilerText.isEmpty @@ -207,8 +204,11 @@ class BaseStatusTableViewCell: UITableViewCell { } @objc func preferencesChanged() { - guard let mastodonController = mastodonController, let account = mastodonController.persistentContainer.account(for: accountID) else { return } + guard let mastodonController = mastodonController, + let account = mastodonController.persistentContainer.account(for: accountID), + let status = mastodonController.persistentContainer.status(for: statusID) else { return } updateUIForPreferences(account: account) + updateStatusIconsForPreferences(status) } func updateUIForPreferences(account: AccountMO) { @@ -217,6 +217,21 @@ class BaseStatusTableViewCell: UITableViewCell { attachmentsView.contentHidden = Preferences.shared.blurAllMedia || (mastodonController.persistentContainer.status(for: statusID)?.sensitive ?? false) } + func updateStatusIconsForPreferences(_ status: StatusMO) { + visibilityImageView.isHidden = !Preferences.shared.alwaysShowStatusVisibilityIcon + if Preferences.shared.alwaysShowStatusVisibilityIcon { + visibilityImageView.image = UIImage(systemName: status.visibility.unfilledImageName) + visibilityImageView.accessibilityLabel = String(format: NSLocalizedString("Visibility: %@", comment: "status visibility indicator accessibility label"), status.visibility.displayName) + } + let reblogButtonImage: UIImage + if Preferences.shared.alwaysShowStatusVisibilityIcon || reblogButton.isEnabled { + reblogButtonImage = UIImage(systemName: "repeat")! + } else { + reblogButtonImage = UIImage(systemName: status.visibility.imageName)! + } + reblogButton.setImage(reblogButtonImage, for: .normal) + } + override func prepareForReuse() { super.prepareForReuse() diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 1ab4a204b0..359b2ab313 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -89,8 +89,6 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { timestampLabel.isHidden = pinned pinImageView.isHidden = !pinned } - - updateStatusIcons(status) } @objc override func preferencesChanged() { @@ -100,9 +98,6 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) { updateRebloggerLabel(reblogger: reblogger) } - - guard let status = mastodonController.persistentContainer.status(for: statusID) else { return } - updateStatusIcons(status) } private func updateRebloggerLabel(reblogger: AccountMO) { @@ -115,7 +110,9 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { } } - private func updateStatusIcons(_ status: StatusMO) { + override func updateStatusIconsForPreferences(_ status: StatusMO) { + super.updateStatusIconsForPreferences(status) + replyImageView.isHidden = !Preferences.shared.showIsStatusReplyIcon || !showReplyIndicator || status.inReplyToID == nil } diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.xib b/Tusker/Views/Status/TimelineStatusTableViewCell.xib index 0c37b42da1..f5e4645964 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.xib +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.xib @@ -151,36 +151,39 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - + + - - -