From 00bf99334ff7f4bf00878a7f972188465d945861 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 17 Jun 2020 17:45:34 -0400 Subject: [PATCH] Add preference for status reply icons --- Tusker/Preferences/Preferences.swift | 4 ++++ Tusker/Screens/Preferences/AppearancePrefsView.swift | 3 +++ .../Views/Status/TimelineStatusTableViewCell.swift | 12 ++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 3543ee44..d6c515ab 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -41,6 +41,7 @@ class Preferences: Codable, ObservableObject { self.showRepliesInProfiles = try container.decode(Bool.self, forKey: .showRepliesInProfiles) 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.defaultPostVisibility = try container.decode(Status.Visibility.self, forKey: .defaultPostVisibility) self.automaticallySaveDrafts = try container.decode(Bool.self, forKey: .automaticallySaveDrafts) @@ -69,6 +70,7 @@ class Preferences: Codable, ObservableObject { try container.encode(showRepliesInProfiles, forKey: .showRepliesInProfiles) try container.encode(avatarStyle, forKey: .avatarStyle) try container.encode(hideCustomEmojiInUsernames, forKey: .hideCustomEmojiInUsernames) + try container.encode(showIsStatusReplyIcon, forKey: .showIsStatusReplyIcon) try container.encode(defaultPostVisibility, forKey: .defaultPostVisibility) try container.encode(automaticallySaveDrafts, forKey: .automaticallySaveDrafts) @@ -95,6 +97,7 @@ class Preferences: Codable, ObservableObject { @Published var showRepliesInProfiles = false @Published var avatarStyle = AvatarStyle.roundRect @Published var hideCustomEmojiInUsernames = false + @Published var showIsStatusReplyIcon = false // MARK: Composing @Published var defaultPostVisibility = Status.Visibility.public @@ -125,6 +128,7 @@ class Preferences: Codable, ObservableObject { case showRepliesInProfiles case avatarStyle case hideCustomEmojiInUsernames + case showIsStatusReplyIcon case defaultPostVisibility case automaticallySaveDrafts diff --git a/Tusker/Screens/Preferences/AppearancePrefsView.swift b/Tusker/Screens/Preferences/AppearancePrefsView.swift index 96e68531..272e460e 100644 --- a/Tusker/Screens/Preferences/AppearancePrefsView.swift +++ b/Tusker/Screens/Preferences/AppearancePrefsView.swift @@ -39,6 +39,9 @@ struct AppearancePrefsView : View { Toggle(isOn: $preferences.hideCustomEmojiInUsernames) { Text("Hide Custom Emoji in Usernames") } + Toggle(isOn: $preferences.showIsStatusReplyIcon) { + Text("Show Status Reply Icons") + } } .listStyle(GroupedListStyle()) .navigationBarTitle(Text("Appearance")) diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index b494c6e6..1ab4a204 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -89,16 +89,20 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { timestampLabel.isHidden = pinned pinImageView.isHidden = !pinned } - - replyImageView.isHidden = !showReplyIndicator || status.inReplyToID == nil + + updateStatusIcons(status) } @objc override func preferencesChanged() { super.preferencesChanged() + if let rebloggerID = rebloggerID, 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) { @@ -111,6 +115,10 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { } } + private func updateStatusIcons(_ status: StatusMO) { + replyImageView.isHidden = !Preferences.shared.showIsStatusReplyIcon || !showReplyIndicator || status.inReplyToID == nil + } + func updateTimestamp() { // if the mastodonController is nil (i.e. the delegate is nil), then the screen this cell was a part of has been deallocated // so we bail out immediately, since there's nothing to update