import Foundation
import ThreemaMacros
class MultiDeviceCell: ThemedCodeStackTableViewCell {
// MARK: - Public property
var deviceInfo: DeviceInfo? {
didSet {
guard let deviceInfo else {
return
}
switch deviceInfo.platform {
case .ios, .android:
platformIcon.image = UIImage(systemName: "iphone")
case .desktop, .web, .unspecified:
platformIcon.image = UIImage(systemName: "desktopcomputer")
}
deviceInfoLabel.text = deviceInfo.label
badgeLabel.text = deviceInfo.badge
// Badge label with padding
if deviceInfo.badge?.count ?? 0 > 0 {
badgeView.backgroundColor = .lightGray
badgeView.layer.masksToBounds = true
badgeView.layer.cornerRadius = 4.0
let padding = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)
badgeLabel.snp.makeConstraints { make in
make.edges.equalTo(self.badgeView).inset(padding)
}
badgeView.isHidden = false
}
else {
badgeView.isHidden = true
}
platformDetailsLabel.text = deviceInfo.platformDetails
lastLoginAtLabel.text = String.localizedStringWithFormat(
#localize("multi_device_linked_devices_last_login"),
DateFormatter.relativeLongStyleDateShortStyleTime(deviceInfo.lastLoginAt)
)
}
}
// MARK: - Private properties
// MARK: Subviews
lazy var platformIcon: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.heightAnchor.constraint(equalToConstant: 40.0).isActive = true
imageView.widthAnchor.constraint(equalToConstant: 40.0).isActive = true
return imageView
}()
lazy var platformStack: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [deviceInfoStack, detailsStack])
stackView.axis = .vertical
stackView.spacing = 4
stackView.alignment = .fill
stackView.distribution = .fill
stackView.translatesAutoresizingMaskIntoConstraints = false
return stackView
}()
private lazy var deviceInfoStack: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [deviceInfoLabel, badgeView])
stackView.axis = .horizontal
stackView.spacing = 8
stackView.alignment = .fill
stackView.distribution = .equalSpacing
stackView.translatesAutoresizingMaskIntoConstraints = false
return stackView
}()
private lazy var detailsStack: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [platformDetailsLabel, lastLoginAtLabel])
stackView.axis = .vertical
stackView.spacing = 2
stackView.alignment = .fill
stackView.distribution = .fill
stackView.translatesAutoresizingMaskIntoConstraints = false
return stackView
}()
private lazy var platformDetailsLabel: UILabel = {
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .footnote)
label.textColor = .secondaryLabel
label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
label.numberOfLines = 0
}
return label
}()
private lazy var lastLoginAtLabel: UILabel = {
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .footnote)
label.textColor = .secondaryLabel
label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
label.numberOfLines = 0
}
return label
}()
private lazy var deviceInfoLabel: UILabel = {
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .body).bold()
label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
label.numberOfLines = 0
}
return label
}()
private lazy var badgeView: UIView = {
let view = UIView()
view.addSubview(badgeLabel)
return view
}()
private lazy var badgeLabel: UILabel = {
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .caption1).bold()
label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
label.numberOfLines = 0
}
return label
}()
// MARK: - Lifecycle
override func configureCell() {
super.configureCell()
contentStack.distribution = .fill
contentStack.spacing = 16
contentStack.addArrangedSubview(platformIcon)
contentStack.addArrangedSubview(platformStack)
}
}
// MARK: - Reusable
extension MultiDeviceCell: Reusable { }
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet am 2026-11-04)
¤
*© Formatika GbR, Deutschland