session-ios/Session/Conversations/Views & Modals/ConversationTitleView.swift

111 lines
3.7 KiB
Swift
Raw Normal View History

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
2021-02-15 06:50:48 +01:00
import UIKit
import SessionUIKit
import SessionMessagingKit
import SessionUtilitiesKit
2021-02-15 06:50:48 +01:00
final class ConversationTitleView: UIView {
2021-02-15 06:50:48 +01:00
override var intrinsicContentSize: CGSize {
return UIView.layoutFittingExpandedSize
}
// MARK: - UI Components
2021-02-15 06:50:48 +01:00
private lazy var titleLabel: UILabel = {
let result: UILabel = UILabel()
2021-02-15 06:50:48 +01:00
result.textColor = Colors.text
result.font = .boldSystemFont(ofSize: Values.mediumFontSize)
result.lineBreakMode = .byTruncatingTail
2021-02-15 06:50:48 +01:00
return result
}()
private lazy var subtitleLabel: UILabel = {
let result: UILabel = UILabel()
2021-02-15 06:50:48 +01:00
result.textColor = Colors.text
result.font = .systemFont(ofSize: 13)
result.lineBreakMode = .byTruncatingTail
2021-02-15 06:50:48 +01:00
return result
}()
// MARK: - Initialization
init() {
super.init(frame: .zero)
let stackView: UIStackView = UIStackView(arrangedSubviews: [ titleLabel, subtitleLabel ])
2021-02-15 06:50:48 +01:00
stackView.axis = .vertical
stackView.alignment = .center
stackView.isLayoutMarginsRelativeArrangement = true
addSubview(stackView)
2021-02-15 06:50:48 +01:00
stackView.pin(to: self)
}
required init?(coder: NSCoder) {
preconditionFailure("Use init() instead.")
2021-02-15 06:50:48 +01:00
}
// MARK: - Content
public func update(
with name: String,
notificationMode: SessionThread.NotificationMode,
userCount: Int?
) {
guard Thread.isMainThread else {
DispatchQueue.main.async { [weak self] in
self?.update(with: name, notificationMode: notificationMode, userCount: userCount)
2021-02-15 06:50:48 +01:00
}
return
2021-02-15 06:50:48 +01:00
}
// Generate the subtitle
let subtitle: NSAttributedString? = {
switch notificationMode {
case .none:
return NSAttributedString(
string: "\u{e067} ",
attributes: [
.font: UIFont.ows_elegantIconsFont(10),
.foregroundColor: Colors.text
]
)
.appending(string: "Muted")
case .mentionsOnly:
// FIXME: This is going to have issues when swapping between light/dark mode
let imageAttachment = NSTextAttachment()
let color: UIColor = (isDarkMode ? .white : .black)
imageAttachment.image = UIImage(named: "NotifyMentions.png")?.asTintedImage(color: color)
imageAttachment.bounds = CGRect(
x: 0,
y: -2,
width: Values.smallFontSize,
height: Values.smallFontSize
)
return NSAttributedString(attachment: imageAttachment)
.appending(string: " ")
.appending(string: "view_conversation_title_notify_for_mentions_only".localized())
case .all:
guard let userCount: Int = userCount else { return nil }
return NSAttributedString(string: "\(userCount) member\(userCount == 1 ? "" : "s")")
}
}()
self.titleLabel.text = name
self.titleLabel.font = .boldSystemFont(
ofSize: (subtitle != nil ?
Values.mediumFontSize :
Values.veryLargeFontSize
)
)
self.subtitleLabel.attributedText = subtitle
2021-03-01 05:15:37 +01:00
}
}