metatext/Views/UIKit/AccountHeaderView.swift

541 lines
26 KiB
Swift
Raw Normal View History

2020-09-22 06:53:11 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
2021-02-22 23:59:33 +00:00
import SDWebImage
2020-09-22 06:53:11 +00:00
import UIKit
import ViewModels
2021-02-04 01:50:25 +00:00
// swiftlint:disable file_length
2020-11-09 06:22:20 +00:00
final class AccountHeaderView: UIView {
2021-01-19 07:29:00 +00:00
let headerImageBackgroundView = UIView()
2021-02-22 23:59:33 +00:00
let headerImageView = SDAnimatedImageView()
2020-10-22 22:16:06 +00:00
let headerButton = UIButton()
let avatarBackgroundView = UIView()
2021-02-22 23:59:33 +00:00
let avatarImageView = SDAnimatedImageView()
2020-11-10 06:27:08 +00:00
let avatarButton = UIButton()
2020-11-12 08:32:18 +00:00
let relationshipButtonsStackView = UIStackView()
2021-03-02 00:53:36 +00:00
let directMessageButton = UIButton()
2020-11-12 08:32:18 +00:00
let followButton = UIButton(type: .system)
let unfollowButton = UIButton(type: .system)
2021-02-26 06:22:40 +00:00
let notifyButton = UIButton()
let unnotifyButton = UIButton()
2021-02-22 07:10:34 +00:00
let displayNameLabel = AnimatedAttachmentLabel()
2020-11-11 00:53:31 +00:00
let accountStackView = UIStackView()
2021-03-01 22:52:08 +00:00
let accountLabel = CopyableLabel()
2020-11-11 00:53:31 +00:00
let lockedImageView = UIImageView()
2021-02-11 02:04:04 +00:00
let followsYouLabel = CapsuleLabel()
let mutedLabel = CapsuleLabel()
let blockedLabel = CapsuleLabel()
2021-02-11 05:20:42 +00:00
let statusCountJoinedStackView = UIStackView()
let statusCountLabel = UILabel()
let statusCountJoinedSeparatorLabel = UILabel()
let joinedLabel = UILabel()
2020-11-10 06:27:08 +00:00
let fieldsStackView = UIStackView()
2020-09-22 06:53:11 +00:00
let noteTextView = TouchFallthroughTextView()
2020-12-03 01:06:46 +00:00
let followStackView = UIStackView()
let followingButton = UIButton()
let followersButton = UIButton()
2020-09-22 06:53:11 +00:00
let segmentedControl = UISegmentedControl()
2021-01-31 00:38:56 +00:00
let unavailableLabel = UILabel()
2020-09-22 06:53:11 +00:00
2021-01-31 01:43:48 +00:00
var viewModel: ProfileViewModel {
2020-09-22 06:53:11 +00:00
didSet {
2021-01-31 01:43:48 +00:00
if let accountViewModel = viewModel.accountViewModel {
2021-02-22 23:59:33 +00:00
headerImageView.sd_setImage(with: accountViewModel.headerURL) { [weak self] image, _, _, _ in
if let image = image, image.size != Self.missingHeaderImageSize {
2021-01-19 07:29:00 +00:00
self?.headerButton.isEnabled = true
}
}
2020-10-22 22:16:06 +00:00
headerImageView.tag = accountViewModel.headerURL.hashValue
2021-02-02 20:18:15 +00:00
headerButton.accessibilityLabel = String.localizedStringWithFormat(
NSLocalizedString("account.header.accessibility-label-%@", comment: ""),
accountViewModel.displayName)
2021-02-22 23:59:33 +00:00
avatarImageView.sd_setImage(with: accountViewModel.avatarURL(profile: true))
2020-11-10 06:27:08 +00:00
avatarImageView.tag = accountViewModel.avatarURL(profile: true).hashValue
2021-02-02 20:18:15 +00:00
avatarButton.accessibilityLabel = String.localizedStringWithFormat(
NSLocalizedString("account.avatar.accessibility-label-%@", comment: ""),
accountViewModel.displayName)
2020-11-10 06:27:08 +00:00
2020-11-12 08:32:18 +00:00
if !accountViewModel.isSelf, let relationship = accountViewModel.relationship {
2021-01-31 18:43:37 +00:00
followsYouLabel.isHidden = !relationship.followedBy
2021-02-11 02:04:04 +00:00
mutedLabel.isHidden = !relationship.muting
blockedLabel.isHidden = !relationship.blocking
2020-11-12 08:32:18 +00:00
followButton.setTitle(
NSLocalizedString(
accountViewModel.isLocked ? "account.request" : "account.follow",
comment: ""),
for: .normal)
2021-02-06 04:47:20 +00:00
followButton.isHidden = relationship.following || relationship.requested
unfollowButton.isHidden = !(relationship.following || relationship.requested)
unfollowButton.setTitle(
NSLocalizedString(
2021-03-01 22:55:03 +00:00
relationship.requested ? "account.request.cancel" : "account.following",
2021-02-06 04:47:20 +00:00
comment: ""),
for: .normal)
2020-11-12 08:32:18 +00:00
2021-02-26 06:22:40 +00:00
if relationship.following, let notifying = relationship.notifying {
if notifying {
notifyButton.isHidden = true
unnotifyButton.isHidden = false
} else {
notifyButton.isHidden = false
unnotifyButton.isHidden = true
}
} else {
notifyButton.isHidden = true
unnotifyButton.isHidden = true
}
2020-11-12 08:32:18 +00:00
relationshipButtonsStackView.isHidden = false
2021-01-31 00:38:56 +00:00
unavailableLabel.isHidden = !relationship.blockedBy
2020-11-12 08:32:18 +00:00
} else {
relationshipButtonsStackView.isHidden = true
2021-01-31 00:38:56 +00:00
unavailableLabel.isHidden = true
2020-11-12 08:32:18 +00:00
}
2020-11-10 06:27:08 +00:00
if accountViewModel.displayName.isEmpty {
displayNameLabel.isHidden = true
} else {
let mutableDisplayName = NSMutableAttributedString(string: accountViewModel.displayName)
2021-02-22 07:10:34 +00:00
mutableDisplayName.insert(emojis: accountViewModel.emojis,
view: displayNameLabel,
identityContext: viewModel.identityContext)
2020-11-10 06:27:08 +00:00
mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight)
displayNameLabel.attributedText = mutableDisplayName
}
accountLabel.text = accountViewModel.accountName
2020-11-11 00:53:31 +00:00
lockedImageView.isHidden = !accountViewModel.isLocked
2020-11-10 06:27:08 +00:00
2021-02-03 23:00:32 +00:00
var accountStackViewAccessibilityLabel = accountViewModel.accountName
if !lockedImageView.isHidden {
accountStackViewAccessibilityLabel
.appendWithSeparator(NSLocalizedString("account.locked.accessibility-label", comment: ""))
}
if !followsYouLabel.isHidden, let followsYouText = followsYouLabel.text {
accountStackViewAccessibilityLabel.appendWithSeparator(followsYouText)
}
accountStackView.accessibilityLabel = accountStackViewAccessibilityLabel
2021-02-11 05:20:42 +00:00
let statusCountFormat: String
switch viewModel.identityContext.appPreferences.statusWord {
case .toot:
statusCountFormat = NSLocalizedString("statuses.count.toot-%ld", comment: "")
case .post:
statusCountFormat = NSLocalizedString("statuses.count.post-%ld", comment: "")
}
statusCountLabel.text = String.localizedStringWithFormat(
statusCountFormat,
accountViewModel.statusesCount)
joinedLabel.text = String.localizedStringWithFormat(
NSLocalizedString("account.joined-%@", comment: ""),
Self.joinedDateFormatter.string(from: accountViewModel.joined))
2020-11-10 06:27:08 +00:00
for view in fieldsStackView.arrangedSubviews {
fieldsStackView.removeArrangedSubview(view)
view.removeFromSuperview()
}
for identityProof in accountViewModel.identityProofs {
let fieldView = AccountFieldView(
name: identityProof.provider,
value: NSAttributedString(
string: identityProof.providerUsername,
attributes: [.link: identityProof.profileUrl]),
verifiedAt: identityProof.updatedAt,
2021-02-22 07:10:34 +00:00
emojis: [],
identityContext: viewModel.identityContext)
fieldView.valueTextView.delegate = self
fieldsStackView.addArrangedSubview(fieldView)
}
2020-11-10 06:27:08 +00:00
for field in accountViewModel.fields {
let fieldView = AccountFieldView(
name: field.name,
value: field.value.attributed,
verifiedAt: field.verifiedAt,
2021-02-22 07:10:34 +00:00
emojis: accountViewModel.emojis,
identityContext: viewModel.identityContext)
2020-11-10 06:27:08 +00:00
fieldView.valueTextView.delegate = self
fieldsStackView.addArrangedSubview(fieldView)
}
2021-01-18 00:39:47 +00:00
fieldsStackView.isHidden = accountViewModel.fields.isEmpty && accountViewModel.identityProofs.isEmpty
2020-09-22 06:53:11 +00:00
let noteFont = UIFont.preferredFont(forTextStyle: .callout)
2020-09-26 07:13:50 +00:00
let mutableNote = NSMutableAttributedString(attributedString: accountViewModel.note)
2020-09-22 06:53:11 +00:00
let noteRange = NSRange(location: 0, length: mutableNote.length)
mutableNote.removeAttribute(.font, range: noteRange)
mutableNote.addAttributes(
[.font: noteFont as Any,
.foregroundColor: UIColor.label],
range: noteRange)
2021-02-22 07:10:34 +00:00
mutableNote.insert(emojis: accountViewModel.emojis,
view: noteTextView,
identityContext: viewModel.identityContext)
2020-09-22 06:53:11 +00:00
mutableNote.resizeAttachments(toLineHeight: noteFont.lineHeight)
noteTextView.attributedText = mutableNote
noteTextView.isHidden = false
2020-12-03 01:06:46 +00:00
followingButton.setAttributedLocalizedTitle(
localizationKey: "account.following-count",
count: accountViewModel.followingCount)
followersButton.setAttributedLocalizedTitle(
localizationKey: "account.followers-count",
count: accountViewModel.followersCount)
followStackView.isHidden = false
2020-09-22 06:53:11 +00:00
} else {
noteTextView.isHidden = true
2020-12-03 01:06:46 +00:00
followStackView.isHidden = true
2020-09-22 06:53:11 +00:00
}
}
}
2021-01-31 01:43:48 +00:00
init(viewModel: ProfileViewModel) {
self.viewModel = viewModel
// Initial size is to avoid unsatisfiable constraint warning
super.init(frame: .init(origin: .zero, size: .init(width: 300, height: 300)))
2020-09-22 06:53:11 +00:00
2020-10-13 20:11:27 +00:00
initialSetup()
2020-09-22 06:53:11 +00:00
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
2020-11-12 08:32:18 +00:00
override func layoutSubviews() {
super.layoutSubviews()
2021-03-02 00:53:36 +00:00
if let pointSize = followingButton.titleLabel?.font.pointSize {
relationshipButtonsStackView.heightAnchor
.constraint(equalToConstant: pointSize + .defaultSpacing * 2).isActive = true
}
for button in [followButton, unfollowButton] {
let inset = (button.bounds.height - (button.titleLabel?.bounds.height ?? 0))
2020-11-12 08:32:18 +00:00
button.contentEdgeInsets = .init(top: 0, left: inset, bottom: 0, right: inset)
2021-03-02 00:53:36 +00:00
}
for button in [directMessageButton, followButton, unfollowButton, notifyButton, unnotifyButton] {
2020-11-12 08:32:18 +00:00
button.layer.cornerRadius = button.bounds.height / 2
}
}
2020-09-22 06:53:11 +00:00
}
2020-09-26 07:45:39 +00:00
extension AccountHeaderView: UITextViewDelegate {
func textView(
_ textView: UITextView,
shouldInteractWith URL: URL,
in characterRange: NSRange,
interaction: UITextItemInteraction) -> Bool {
switch interaction {
case .invokeDefaultAction:
2021-01-31 01:43:48 +00:00
viewModel.accountViewModel?.urlSelected(URL)
2020-09-26 07:45:39 +00:00
return false
case .preview: return false
case .presentActions: return false
@unknown default: return false
}
}
}
2020-09-22 06:53:11 +00:00
private extension AccountHeaderView {
2020-11-10 06:27:08 +00:00
static let avatarDimension = CGFloat.avatarDimension * 2
2021-01-19 07:29:00 +00:00
static let missingHeaderImageSize = CGSize(width: 1, height: 1)
2021-02-11 05:20:42 +00:00
static let joinedDateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .short
return formatter
}()
2020-11-10 06:27:08 +00:00
2020-10-22 22:16:06 +00:00
// swiftlint:disable:next function_body_length
2020-10-13 20:11:27 +00:00
func initialSetup() {
2020-09-22 06:53:11 +00:00
let baseStackView = UIStackView()
2021-01-19 07:29:00 +00:00
addSubview(headerImageBackgroundView)
headerImageBackgroundView.translatesAutoresizingMaskIntoConstraints = false
headerImageBackgroundView.backgroundColor = .secondarySystemBackground
2020-09-22 06:53:11 +00:00
addSubview(headerImageView)
headerImageView.translatesAutoresizingMaskIntoConstraints = false
2020-09-28 05:22:01 +00:00
headerImageView.contentMode = .scaleAspectFill
headerImageView.clipsToBounds = true
2020-10-22 22:16:06 +00:00
headerImageView.isUserInteractionEnabled = true
headerImageView.addSubview(headerButton)
headerButton.translatesAutoresizingMaskIntoConstraints = false
headerButton.setBackgroundImage(.highlightedButtonBackground, for: .highlighted)
2021-01-31 01:43:48 +00:00
headerButton.addAction(UIAction { [weak self] _ in self?.viewModel.presentHeader() }, for: .touchUpInside)
2021-01-19 07:29:00 +00:00
headerButton.isEnabled = false
2020-11-10 06:27:08 +00:00
let avatarBackgroundViewDimension = Self.avatarDimension + .compactSpacing * 2
addSubview(avatarBackgroundView)
avatarBackgroundView.translatesAutoresizingMaskIntoConstraints = false
avatarBackgroundView.backgroundColor = .systemBackground
avatarBackgroundView.layer.cornerRadius = avatarBackgroundViewDimension / 2
avatarBackgroundView.addSubview(avatarImageView)
2020-11-10 06:27:08 +00:00
avatarImageView.translatesAutoresizingMaskIntoConstraints = false
avatarImageView.contentMode = .scaleAspectFill
avatarImageView.clipsToBounds = true
avatarImageView.isUserInteractionEnabled = true
avatarImageView.layer.cornerRadius = Self.avatarDimension / 2
avatarImageView.addSubview(avatarButton)
avatarButton.translatesAutoresizingMaskIntoConstraints = false
avatarButton.setBackgroundImage(.highlightedButtonBackground, for: .highlighted)
2021-01-31 01:43:48 +00:00
avatarButton.addAction(UIAction { [weak self] _ in self?.viewModel.presentAvatar() }, for: .touchUpInside)
2020-10-22 22:16:06 +00:00
2020-11-12 08:32:18 +00:00
addSubview(relationshipButtonsStackView)
relationshipButtonsStackView.translatesAutoresizingMaskIntoConstraints = false
relationshipButtonsStackView.spacing = .defaultSpacing
relationshipButtonsStackView.addArrangedSubview(UIView())
2021-03-02 00:53:36 +00:00
for button in [directMessageButton, notifyButton, unnotifyButton, followButton, unfollowButton] {
2020-11-12 08:32:18 +00:00
relationshipButtonsStackView.addArrangedSubview(button)
button.titleLabel?.font = .preferredFont(forTextStyle: .headline)
button.titleLabel?.adjustsFontForContentSizeCategory = true
button.backgroundColor = .secondarySystemBackground
}
2021-03-02 00:53:36 +00:00
directMessageButton.setImage(
UIImage(
systemName: "envelope",
withConfiguration: UIImage.SymbolConfiguration(scale: .small)),
for: .normal)
directMessageButton.accessibilityLabel = NSLocalizedString("account.direct-message", comment: "")
directMessageButton.addAction(
UIAction { [weak self] _ in self?.viewModel.sendDirectMessage() },
for: .touchUpInside)
2020-11-12 08:32:18 +00:00
followButton.setImage(
UIImage(
systemName: "person.badge.plus",
withConfiguration: UIImage.SymbolConfiguration(scale: .small)),
for: .normal)
2021-02-26 06:22:40 +00:00
followButton.isHidden = true
2021-03-02 00:53:36 +00:00
followButton.titleLabel?.adjustsFontSizeToFitWidth = true
2020-11-12 08:32:18 +00:00
followButton.addAction(
2021-01-31 01:43:48 +00:00
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.follow() },
2020-11-12 08:32:18 +00:00
for: .touchUpInside)
unfollowButton.setImage(
UIImage(
systemName: "checkmark",
withConfiguration: UIImage.SymbolConfiguration(scale: .small)),
for: .normal)
2021-03-01 22:55:03 +00:00
unfollowButton.setTitle(NSLocalizedString("account.following", comment: ""), for: .normal)
2021-02-26 06:22:40 +00:00
unfollowButton.isHidden = true
2021-03-02 00:53:36 +00:00
unfollowButton.titleLabel?.adjustsFontSizeToFitWidth = true
2021-02-11 03:52:21 +00:00
unfollowButton.addAction(
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.confirmUnfollow() },
for: .touchUpInside)
2020-11-12 08:32:18 +00:00
2021-02-26 06:22:40 +00:00
notifyButton.setImage(
UIImage(systemName: "bell",
2021-03-02 00:53:36 +00:00
withConfiguration: UIImage.SymbolConfiguration(scale: .medium)),
2021-02-26 06:22:40 +00:00
for: .normal)
2021-03-02 00:53:36 +00:00
notifyButton.imageView?.contentMode = .scaleAspectFit
2021-02-26 06:22:40 +00:00
notifyButton.accessibilityLabel = NSLocalizedString("account.notify", comment: "")
notifyButton.tintColor = .secondaryLabel
notifyButton.isHidden = true
notifyButton.addAction(
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.notify() },
for: .touchUpInside)
unnotifyButton.setImage(
UIImage(systemName: "bell.fill",
2021-03-02 00:53:36 +00:00
withConfiguration: UIImage.SymbolConfiguration(scale: .medium)),
2021-02-26 06:22:40 +00:00
for: .normal)
unnotifyButton.accessibilityLabel = NSLocalizedString("account.unnotify", comment: "")
unnotifyButton.isHidden = true
unnotifyButton.addAction(
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.unnotify() },
for: .touchUpInside)
2020-10-22 22:16:06 +00:00
addSubview(baseStackView)
2020-09-22 06:53:11 +00:00
baseStackView.translatesAutoresizingMaskIntoConstraints = false
baseStackView.axis = .vertical
2020-11-10 06:27:08 +00:00
baseStackView.spacing = .defaultSpacing
baseStackView.addArrangedSubview(displayNameLabel)
displayNameLabel.numberOfLines = 0
displayNameLabel.font = .preferredFont(forTextStyle: .headline)
displayNameLabel.adjustsFontForContentSizeCategory = true
2020-11-11 00:53:31 +00:00
baseStackView.addArrangedSubview(accountStackView)
2021-01-31 18:43:37 +00:00
accountStackView.spacing = .compactSpacing
2021-02-03 23:00:32 +00:00
accountStackView.isAccessibilityElement = true
2020-11-11 00:53:31 +00:00
accountStackView.addArrangedSubview(accountLabel)
2020-11-10 06:27:08 +00:00
accountLabel.numberOfLines = 0
accountLabel.font = .preferredFont(forTextStyle: .subheadline)
accountLabel.adjustsFontForContentSizeCategory = true
accountLabel.textColor = .secondaryLabel
2020-11-11 00:53:31 +00:00
accountLabel.setContentHuggingPriority(.required, for: .horizontal)
accountLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
accountStackView.addArrangedSubview(lockedImageView)
lockedImageView.image = UIImage(
systemName: "lock.fill",
withConfiguration: UIImage.SymbolConfiguration(scale: .small))
lockedImageView.tintColor = .secondaryLabel
lockedImageView.contentMode = .scaleAspectFit
2021-01-31 18:43:37 +00:00
accountStackView.addArrangedSubview(followsYouLabel)
followsYouLabel.text = NSLocalizedString("account.follows-you", comment: "")
followsYouLabel.isHidden = true
2021-02-11 02:04:04 +00:00
accountStackView.addArrangedSubview(mutedLabel)
mutedLabel.text = NSLocalizedString("account.muted", comment: "")
mutedLabel.isHidden = true
accountStackView.addArrangedSubview(blockedLabel)
blockedLabel.text = NSLocalizedString("account.blocked", comment: "")
blockedLabel.isHidden = true
2020-11-11 00:53:31 +00:00
accountStackView.addArrangedSubview(UIView())
2020-11-10 06:27:08 +00:00
2021-02-11 05:20:42 +00:00
baseStackView.addArrangedSubview(statusCountJoinedStackView)
statusCountJoinedStackView.spacing = .compactSpacing
statusCountJoinedStackView.addArrangedSubview(statusCountLabel)
statusCountLabel.font = .preferredFont(forTextStyle: .footnote)
statusCountLabel.adjustsFontForContentSizeCategory = true
statusCountLabel.textColor = .tertiaryLabel
statusCountLabel.setContentHuggingPriority(.required, for: .horizontal)
statusCountLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
statusCountJoinedStackView.addArrangedSubview(statusCountJoinedSeparatorLabel)
statusCountJoinedSeparatorLabel.font = .preferredFont(forTextStyle: .footnote)
statusCountJoinedSeparatorLabel.adjustsFontForContentSizeCategory = true
statusCountJoinedSeparatorLabel.textColor = .tertiaryLabel
statusCountJoinedSeparatorLabel.setContentHuggingPriority(.required, for: .horizontal)
statusCountJoinedSeparatorLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
statusCountJoinedSeparatorLabel.text = ""
statusCountJoinedSeparatorLabel.isAccessibilityElement = false
statusCountJoinedStackView.addArrangedSubview(joinedLabel)
joinedLabel.font = .preferredFont(forTextStyle: .footnote)
joinedLabel.adjustsFontForContentSizeCategory = true
joinedLabel.textColor = .tertiaryLabel
joinedLabel.setContentHuggingPriority(.required, for: .horizontal)
joinedLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
statusCountJoinedStackView.addArrangedSubview(UIView())
2020-11-10 06:27:08 +00:00
baseStackView.addArrangedSubview(fieldsStackView)
fieldsStackView.axis = .vertical
fieldsStackView.spacing = .hairline
fieldsStackView.backgroundColor = .separator
fieldsStackView.clipsToBounds = true
fieldsStackView.layer.borderColor = UIColor.separator.cgColor
fieldsStackView.layer.borderWidth = .hairline
fieldsStackView.layer.cornerRadius = .defaultCornerRadius
2021-02-11 02:11:21 +00:00
fieldsStackView.isHidden = true
2020-09-22 06:53:11 +00:00
2020-11-10 06:27:08 +00:00
baseStackView.addArrangedSubview(noteTextView)
2020-09-26 07:45:39 +00:00
noteTextView.delegate = self
2020-09-22 06:53:11 +00:00
2020-12-03 01:06:46 +00:00
baseStackView.addArrangedSubview(followStackView)
followStackView.distribution = .fillEqually
followingButton.addAction(
2021-01-31 01:43:48 +00:00
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.followingSelected() },
2020-12-03 01:06:46 +00:00
for: .touchUpInside)
followStackView.addArrangedSubview(followingButton)
followersButton.addAction(
2021-01-31 01:43:48 +00:00
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.followersSelected() },
2020-12-03 01:06:46 +00:00
for: .touchUpInside)
followStackView.addArrangedSubview(followersButton)
2021-01-31 01:43:48 +00:00
let statusWord = viewModel.identityContext.appPreferences.statusWord
2020-09-27 02:03:53 +00:00
for (index, collection) in ProfileCollection.allCases.enumerated() {
2020-09-22 06:53:11 +00:00
segmentedControl.insertSegment(
2021-01-31 01:43:48 +00:00
action: UIAction(title: collection.title(statusWord: statusWord)) { [weak self] _ in
self?.viewModel.collection = collection
self?.viewModel.request(maxId: nil, minId: nil, search: nil)
2020-09-22 06:53:11 +00:00
},
at: index,
animated: false)
}
segmentedControl.selectedSegmentIndex = 0
baseStackView.addArrangedSubview(segmentedControl)
2021-01-31 00:38:56 +00:00
baseStackView.addArrangedSubview(unavailableLabel)
unavailableLabel.adjustsFontForContentSizeCategory = true
unavailableLabel.font = .preferredFont(forTextStyle: .title3)
unavailableLabel.textAlignment = .center
unavailableLabel.numberOfLines = 0
unavailableLabel.text = NSLocalizedString("account.unavailable", comment: "")
unavailableLabel.isHidden = true
2020-09-22 06:53:11 +00:00
let headerImageAspectRatioConstraint = headerImageView.heightAnchor.constraint(
equalTo: headerImageView.widthAnchor,
2020-09-28 05:22:01 +00:00
multiplier: 1 / 3)
2020-09-22 06:53:11 +00:00
2020-10-12 05:37:34 +00:00
headerImageAspectRatioConstraint.priority = .justBelowMax
2020-09-22 06:53:11 +00:00
NSLayoutConstraint.activate([
headerImageAspectRatioConstraint,
headerImageView.topAnchor.constraint(equalTo: topAnchor),
headerImageView.leadingAnchor.constraint(equalTo: leadingAnchor),
headerImageView.trailingAnchor.constraint(equalTo: trailingAnchor),
2021-01-19 07:29:00 +00:00
headerImageBackgroundView.leadingAnchor.constraint(equalTo: headerImageView.leadingAnchor),
headerImageBackgroundView.topAnchor.constraint(equalTo: headerImageView.topAnchor),
headerImageBackgroundView.trailingAnchor.constraint(equalTo: headerImageView.trailingAnchor),
headerImageBackgroundView.bottomAnchor.constraint(equalTo: headerImageView.bottomAnchor),
2020-10-22 22:16:06 +00:00
headerButton.leadingAnchor.constraint(equalTo: headerImageView.leadingAnchor),
headerButton.topAnchor.constraint(equalTo: headerImageView.topAnchor),
headerButton.bottomAnchor.constraint(equalTo: headerImageView.bottomAnchor),
headerButton.trailingAnchor.constraint(equalTo: headerImageView.trailingAnchor),
avatarBackgroundView.heightAnchor.constraint(equalToConstant: avatarBackgroundViewDimension),
avatarBackgroundView.widthAnchor.constraint(equalToConstant: avatarBackgroundViewDimension),
avatarBackgroundView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
avatarBackgroundView.centerYAnchor.constraint(equalTo: headerImageView.bottomAnchor),
2020-11-10 06:27:08 +00:00
avatarImageView.heightAnchor.constraint(equalToConstant: Self.avatarDimension),
avatarImageView.widthAnchor.constraint(equalToConstant: Self.avatarDimension),
avatarImageView.centerXAnchor.constraint(equalTo: avatarBackgroundView.centerXAnchor),
avatarImageView.centerYAnchor.constraint(equalTo: avatarBackgroundView.centerYAnchor),
2020-11-10 06:27:08 +00:00
avatarButton.leadingAnchor.constraint(equalTo: avatarImageView.leadingAnchor),
avatarButton.topAnchor.constraint(equalTo: avatarImageView.topAnchor),
avatarButton.bottomAnchor.constraint(equalTo: avatarImageView.bottomAnchor),
avatarButton.trailingAnchor.constraint(equalTo: avatarImageView.trailingAnchor),
relationshipButtonsStackView.leadingAnchor.constraint(equalTo: avatarBackgroundView.trailingAnchor),
2020-11-12 08:32:18 +00:00
relationshipButtonsStackView.topAnchor.constraint(
equalTo: headerImageView.bottomAnchor,
constant: .defaultSpacing),
relationshipButtonsStackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
2021-03-02 00:53:36 +00:00
directMessageButton.widthAnchor.constraint(equalTo: directMessageButton.heightAnchor),
notifyButton.widthAnchor.constraint(equalTo: notifyButton.heightAnchor),
unnotifyButton.widthAnchor.constraint(equalTo: unnotifyButton.heightAnchor),
baseStackView.topAnchor.constraint(equalTo: avatarBackgroundView.bottomAnchor, constant: .defaultSpacing),
2020-09-22 06:53:11 +00:00
baseStackView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
baseStackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
2020-11-10 06:27:08 +00:00
baseStackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor)
2020-09-22 06:53:11 +00:00
])
}
}
2021-02-04 01:50:25 +00:00
// swiftlint:enable file_length