// // StatusMetaIndicatorsView.swift // Tusker // // Created by Shadowfacts on 1/22/22. // Copyright © 2022 Shadowfacts. All rights reserved. // import UIKit import Pachyderm class StatusMetaIndicatorsView: UIView { var allowedIndicators: Indicator = .all var squeezeHorizontal = false private var images: [UIImageView] = [] func updateUI(status: StatusMO) { images.forEach { $0.removeFromSuperview() } var images: [UIImage] = [] if allowedIndicators.contains(.reply) && Preferences.shared.showIsStatusReplyIcon && status.inReplyToID != nil { images.append(UIImage(systemName: "bubble.left.and.bubble.right")!) } if allowedIndicators.contains(.visibility) && Preferences.shared.alwaysShowStatusVisibilityIcon { images.append(UIImage(systemName: status.visibility.unfilledImageName)!) } if allowedIndicators.contains(.localOnly) && status.localOnly { images.append(UIImage(named: "link.broken")!) } self.images = [] for (index, image) in images.enumerated() { let v = UIImageView(image: image) v.translatesAutoresizingMaskIntoConstraints = false v.contentMode = .scaleAspectFit v.tintColor = .secondaryLabel v.preferredSymbolConfiguration = .init(weight: .thin) addSubview(v) v.heightAnchor.constraint(equalToConstant: 22).isActive = true if index % 2 == 0 { if index == images.count - 1 { v.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true v.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor).isActive = true } else { v.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true } } else { if squeezeHorizontal { v.leadingAnchor.constraint(equalTo: self.images[index - 1].trailingAnchor, constant: 4).isActive = true } else { v.leadingAnchor.constraint(greaterThanOrEqualTo: self.images[index - 1].trailingAnchor, constant: 4).isActive = true } v.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true } let row = index / 2 if row == 0 { v.topAnchor.constraint(equalTo: topAnchor).isActive = true } else { v.topAnchor.constraint(equalTo: self.images[index - 1].bottomAnchor, constant: 4).isActive = true } v.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor).isActive = true self.images.append(v) } } } extension StatusMetaIndicatorsView { struct Indicator: OptionSet { let rawValue: Int static let reply = Indicator(rawValue: 1 << 0) static let visibility = Indicator(rawValue: 1 << 1) static let localOnly = Indicator(rawValue: 1 << 2) static let all: Indicator = [.reply, .visibility, .localOnly] } }