mirror of https://github.com/oxen-io/session-ios
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.
103 lines
3.3 KiB
Swift
103 lines
3.3 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import UIKit
|
|
import SessionUIKit
|
|
import SessionMessagingKit
|
|
|
|
final class SimplifiedConversationCell: UITableViewCell {
|
|
// MARK: - Initialization
|
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
setUpViewHierarchy()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
setUpViewHierarchy()
|
|
}
|
|
|
|
// MARK: - UI
|
|
|
|
private lazy var stackView: UIStackView = {
|
|
let stackView: UIStackView = UIStackView()
|
|
stackView.translatesAutoresizingMaskIntoConstraints = false
|
|
stackView.axis = .horizontal
|
|
stackView.alignment = .center
|
|
stackView.spacing = Values.mediumSpacing
|
|
|
|
return stackView
|
|
}()
|
|
|
|
private lazy var accentLineView: UIView = {
|
|
let result = UIView()
|
|
result.translatesAutoresizingMaskIntoConstraints = false
|
|
result.backgroundColor = Colors.destructive
|
|
|
|
return result
|
|
}()
|
|
|
|
private lazy var profilePictureView: ProfilePictureView = {
|
|
let view: ProfilePictureView = ProfilePictureView()
|
|
view.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return view
|
|
}()
|
|
|
|
private lazy var displayNameLabel: UILabel = {
|
|
let result = UILabel()
|
|
result.font = .boldSystemFont(ofSize: Values.mediumFontSize)
|
|
result.textColor = Colors.text
|
|
result.lineBreakMode = .byTruncatingTail
|
|
|
|
return result
|
|
}()
|
|
|
|
// MARK: - Initialization
|
|
|
|
private func setUpViewHierarchy() {
|
|
backgroundColor = Colors.cellBackground
|
|
|
|
let selectedBackgroundView = UIView()
|
|
selectedBackgroundView.backgroundColor = Colors.cellSelected
|
|
self.selectedBackgroundView = selectedBackgroundView
|
|
|
|
addSubview(stackView)
|
|
|
|
stackView.addArrangedSubview(accentLineView)
|
|
stackView.addArrangedSubview(profilePictureView)
|
|
stackView.addArrangedSubview(displayNameLabel)
|
|
stackView.addArrangedSubview(UIView.hSpacer(0))
|
|
|
|
setupLayout()
|
|
}
|
|
|
|
// MARK: - Layout
|
|
|
|
private func setupLayout() {
|
|
accentLineView.set(.width, to: Values.accentLineThickness)
|
|
accentLineView.set(.height, to: 68)
|
|
|
|
profilePictureView.set(.width, to: Values.mediumProfilePictureSize)
|
|
profilePictureView.set(.height, to: Values.mediumProfilePictureSize)
|
|
profilePictureView.size = Values.mediumProfilePictureSize
|
|
|
|
stackView.pin(to: self)
|
|
}
|
|
|
|
// MARK: - Updating
|
|
|
|
public func update(with item: ThreadPickerViewModel.Item, currentUserProfile: Profile) {
|
|
accentLineView.alpha = (item.isBlocked ? 1 : 0)
|
|
profilePictureView.update(
|
|
publicKey: item.id,
|
|
profile: item.profile(currentUserProfile: currentUserProfile),
|
|
additionalProfile: item.additionalProfile,
|
|
threadVariant: item.variant,
|
|
openGroupProfilePicture: item.openGroupProfilePictureData.map { UIImage(data: $0) },
|
|
useFallbackPicture: (item.variant == .openGroup && item.openGroupProfilePictureData == nil)
|
|
)
|
|
displayNameLabel.text = item.displayName(currentUserProfile: currentUserProfile)
|
|
}
|
|
}
|