You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/Session/Conversations/Context Menu/ContextMenuVC+MessageInfoVi...

135 lines
5.5 KiB
Swift

// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
import UIKit
import SessionUIKit
import SessionUtilitiesKit
extension ContextMenuVC {
final class MessageInfoView: UIView {
private static let cornerRadius: CGFloat = 8
private let cellViewModel: MessageViewModel
// MARK: - UI
private lazy var messageSentDateLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.smallFontSize)
result.themeTextColor = .textPrimary
result.numberOfLines = 0
return result
}()
private lazy var messageReceivedDateLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.smallFontSize)
result.themeTextColor = .textPrimary
result.numberOfLines = 0
return result
}()
private lazy var profilePictureView: ProfilePictureView = {
let result: ProfilePictureView = ProfilePictureView()
result.set(.height, to: Values.smallProfilePictureSize)
result.size = Values.smallProfilePictureSize
return result
}()
private lazy var displayNameLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .boldSystemFont(ofSize: Values.smallFontSize)
result.themeTextColor = .textPrimary
return result
}()
private lazy var sessionIDLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.verySmallFontSize)
result.themeTextColor = .textPrimary
result.numberOfLines = 0
result.lineBreakMode = .byCharWrapping
return result
}()
// MARK: - Lifecycle
init(cellViewModel: MessageViewModel) {
self.cellViewModel = cellViewModel
super.init(frame: CGRect.zero)
self.accessibilityLabel = "Message info"
setUpViewHierarchy()
}
override init(frame: CGRect) {
preconditionFailure("Use init(cellViewModel:) instead.")
}
required init?(coder: NSCoder) {
preconditionFailure("Use init(cellViewModel:) instead.")
}
private func setUpViewHierarchy() {
let backgroundView: UIView = UIView()
backgroundView.clipsToBounds = true
backgroundView.themeBackgroundColor = .contextMenu_background
backgroundView.layer.cornerRadius = Self.cornerRadius
addSubview(backgroundView)
backgroundView.pin(to: self)
let stackView: UIStackView = UIStackView()
stackView.axis = .vertical
stackView.spacing = Values.smallSpacing
backgroundView.addSubview(stackView)
stackView.pin(to: backgroundView, withInset: Values.mediumSpacing)
messageSentDateLabel.text = "MESSAGE_INFO_SENT".localized() + ":\n" + cellViewModel.dateForUI.fromattedForMessageInfo
stackView.addArrangedSubview(messageSentDateLabel)
messageReceivedDateLabel.text = "MESSAGE_INFO_RECEIVED".localized() + ":\n" + cellViewModel.receivedDateForUI.fromattedForMessageInfo
stackView.addArrangedSubview(messageReceivedDateLabel)
let senderTitleLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.smallFontSize)
result.themeTextColor = .textPrimary
result.text = "MESSAGE_INFO_FROM".localized() + ":"
return result
}()
displayNameLabel.text = cellViewModel.authorName
sessionIDLabel.text = cellViewModel.authorId
profilePictureView.update(
publicKey: cellViewModel.authorId,
profile: cellViewModel.profile,
threadVariant: cellViewModel.threadVariant
)
let profileContainerView: UIView = UIView()
profileContainerView.addSubview(senderTitleLabel)
senderTitleLabel.pin([ UIView.HorizontalEdge.leading, UIView.HorizontalEdge.trailing, UIView.VerticalEdge.top ], to: profileContainerView)
profileContainerView.addSubview(profilePictureView)
profilePictureView.pin(.leading, to: .leading, of: profileContainerView)
profilePictureView.pin(.top, to: .bottom, of: senderTitleLabel, withInset: Values.mediumSpacing)
profilePictureView.pin(.bottom, to: .bottom, of: profileContainerView, withInset: -Values.verySmallSpacing)
let infoContainerStackView: UIStackView = UIStackView(arrangedSubviews: [ displayNameLabel, sessionIDLabel ])
infoContainerStackView.axis = .vertical
profileContainerView.addSubview(infoContainerStackView)
infoContainerStackView.pin(.leading, to: .trailing, of: profilePictureView, withInset: Values.mediumSpacing)
infoContainerStackView.pin(.trailing, to: .trailing, of: profileContainerView)
infoContainerStackView.pin(.bottom, to: .bottom, of: profileContainerView)
infoContainerStackView.set(.width, to: 240)
stackView.addArrangedSubview(profileContainerView)
}
}
}