From 99ef46f457420bee9058743011b673efb0b2b411 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 2 Dec 2022 16:04:09 +1100 Subject: [PATCH] WIP: add banner in conversation screen for outdated client --- Session/Conversations/ConversationVC.swift | 31 ++++++++- .../Views & Modals/InfoBanner.swift | 67 ++++++++++++++++--- .../Translations/en.lproj/Localizable.strings | 2 +- 3 files changed, 85 insertions(+), 15 deletions(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 9756fef1c..f4781091d 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -195,11 +195,11 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl lazy var outdatedClientBanner: InfoBanner = { let info: InfoBanner.Info = InfoBanner.Info( - message: "DISAPPEARING_MESSAGES_OUTDATED_CLIENT_BANNER".localized(), + message: String(format: "DISAPPEARING_MESSAGES_OUTDATED_CLIENT_BANNER".localized(), self.viewModel.threadData.displayName), backgroundColor: .primary, messageFont: .systemFont(ofSize: Values.miniFontSize), - messageTintColor: .text, - height: 20 + messageTintColor: .messageBubble_outgoingText, + height: 40 ) let result: InfoBanner = InfoBanner(info: info) return result @@ -621,6 +621,8 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl userCount: updatedThreadData.userCount, disappearingMessagesConfig: updatedThreadData.disappearingMessagesConfiguration ) + + outdatedClientBanner.update(message: String(format: "DISAPPEARING_MESSAGES_OUTDATED_CLIENT_BANNER".localized(), updatedThreadData.displayName)) } if @@ -685,6 +687,10 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl } } + if initialLoad { + addOrRemoveOutdatedClientBanner(contactIsUsingOutdatedClient: true) + } + if initialLoad || viewModel.threadData.threadIsBlocked != updatedThreadData.threadIsBlocked { addOrRemoveBlockedBanner(threadIsBlocked: (updatedThreadData.threadIsBlocked == true)) } @@ -1247,6 +1253,25 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl } // MARK: - General + + func addOrRemoveOutdatedClientBanner(contactIsUsingOutdatedClient: Bool) { + guard contactIsUsingOutdatedClient else { + UIView.animate( + withDuration: 0.25, + animations: { [weak self] in + self?.outdatedClientBanner.alpha = 0 + }, + completion: { [weak self] _ in + self?.outdatedClientBanner.alpha = 1 + self?.outdatedClientBanner.removeFromSuperview() + } + ) + return + } + + self.view.addSubview(self.outdatedClientBanner) + self.outdatedClientBanner.pin([ UIView.HorizontalEdge.left, UIView.VerticalEdge.top, UIView.HorizontalEdge.right ], to: self.view) + } func addOrRemoveBlockedBanner(threadIsBlocked: Bool) { guard threadIsBlocked else { diff --git a/Session/Conversations/Views & Modals/InfoBanner.swift b/Session/Conversations/Views & Modals/InfoBanner.swift index 454e8f69a..13f878fa2 100644 --- a/Session/Conversations/Views & Modals/InfoBanner.swift +++ b/Session/Conversations/Views & Modals/InfoBanner.swift @@ -30,12 +30,43 @@ final class InfoBanner: UIView { messageTintColor.hash(into: &hasher) height.hash(into: &hasher) } + + func with( + message: String? = nil, + backgroundColor: ThemeValue? = nil, + messageFont: UIFont? = nil, + messageTintColor: ThemeValue? = nil, + height: CGFloat? = nil + ) -> Info { + return Info( + message: message ?? self.message, + backgroundColor: backgroundColor ?? self.backgroundColor, + messageFont: messageFont ?? self.messageFont, + messageTintColor: messageTintColor ?? self.messageTintColor, + height: height ?? self.height + ) + } } + private lazy var label: UILabel = { + let result: UILabel = UILabel() + result.textAlignment = .center + result.lineBreakMode = .byWordWrapping + result.numberOfLines = 0 + + return result + }() + + public var info: Info? + + // MARK: - Initialization + init(info: Info) { super.init(frame: CGRect.zero) - - setUpViewHierarchy(info) + addSubview(label) + label.pin(to: self) + self.set(.height, to: info.height) + self.update(info) } override init(frame: CGRect) { @@ -46,19 +77,33 @@ final class InfoBanner: UIView { preconditionFailure("Use init(coder:) instead.") } - private func setUpViewHierarchy(_ info: InfoBanner.Info) { + // MARK: Update + + private func update(_ info: InfoBanner.Info) { + self.info = info + themeBackgroundColor = info.backgroundColor - let label: UILabel = UILabel() label.font = info.messageFont label.text = info.message label.themeTextColor = info.messageTintColor - label.textAlignment = .center - label.lineBreakMode = .byWordWrapping - label.numberOfLines = 0 - addSubview(label) - - label.center(in: self) - self.set(.height, to: info.height) + } + + public func update( + message: String? = nil, + backgroundColor: ThemeValue? = nil, + messageFont: UIFont? = nil, + messageTintColor: ThemeValue? = nil, + height: CGFloat? = nil + ) { + if let updatedInfo = self.info?.with( + message: message, + backgroundColor: backgroundColor, + messageFont: messageFont, + messageTintColor: messageTintColor, + height: height + ) { + self.update(updatedInfo) + } } } diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index 0c88f6e38..80e736925 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -603,4 +603,4 @@ "MESSAGE_REQUEST_PENDING_APPROVAL_INFO" = "You will be able to send voice messages and attachments once the recipient has approved this message request"; "DISAPPEARING_MESSAGES_TYPE_LEGACY_TITLE" = "Legacy"; "DISAPPEARING_MESSAGES_TYPE_LEGACY_DESCRIPTION" = "Original version of disappearing messages."; -"DISAPPEARING_MESSAGES_OUTDATED_CLIENT_BANNER" = "%@ is using an outdated client. Disappearing messages may not work as expected."; +"DISAPPEARING_MESSAGES_OUTDATED_CLIENT_BANNER" = "%@ is using an outdated client.\nDisappearing messages may not work as expected.";