Files
GitHawk/Classes/Issues/StatusEvent/IssueStatusEventCell.swift
Ryan Nystrom e56c29a9a6 Redesigned Issues interface (#1983)
* clean up title model

* update title style

* organize issue SC method

* remove background colors from styled text in issues

* collection view bg white

* remove card inset and clean up snap superview code

* clean up label design

* thread is root and change base font size

* remove borders on comment cells

* adjust collapse design

* adjust comment line spacing and make non-root body smaller

* refactor detail view

* viewer header background color

* more buttons in reaction cell

* vertical spacers working

* design basically finished;

* scroll to bottom accounts for inset

* PR review background color white

* fixup PR review comments

* spacing on merge and review

* readme background white

* rename to just "spacer"

* horizontal spacing

* fix tests
2018-07-27 11:03:09 -04:00

113 lines
3.9 KiB
Swift

//
// IssueStatusEventCell.swift
// Freetime
//
// Created by Ryan Nystrom on 6/7/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import UIKit
import SnapKit
import StringHelpers
protocol IssueStatusEventCellDelegate: class {
func didTapActor(cell: IssueStatusEventCell)
func didTapHash(cell: IssueStatusEventCell)
}
final class IssueStatusEventCell: UICollectionViewCell {
weak var delegate: IssueStatusEventCellDelegate?
private let actorButton = UIButton()
private let hashButton = UIButton()
private let statusButton = UIButton()
private let dateLabel = ShowMoreDetailsLabel()
private var dateConstraint: Constraint?
override init(frame: CGRect) {
super.init(frame: frame)
actorButton.addTarget(self, action: #selector(IssueStatusEventCell.onActor), for: .touchUpInside)
contentView.addSubview(actorButton)
actorButton.snp.makeConstraints { make in
make.left.equalToSuperview()
make.centerY.equalToSuperview()
}
statusButton.setupAsLabel()
contentView.addSubview(statusButton)
statusButton.snp.makeConstraints { make in
make.left.equalTo(actorButton.snp.right).offset(Styles.Sizes.inlineSpacing)
make.centerY.equalToSuperview()
}
// courier has a little bit of a different kerning, manually adjust
hashButton.titleLabel?.font = Styles.Text.secondaryCode.preferredFont
hashButton.setTitleColor(Styles.Colors.Gray.dark.color, for: .normal)
hashButton.addTarget(self, action: #selector(IssueStatusEventCell.onHash), for: .touchUpInside)
contentView.addSubview(hashButton)
hashButton.snp.makeConstraints { make in
make.left.equalTo(statusButton.snp.right).offset(Styles.Sizes.inlineSpacing)
make.centerY.equalToSuperview().offset(1)
}
dateLabel.font = Styles.Text.secondary.preferredFont
dateLabel.textColor = Styles.Colors.Gray.medium.color
dateLabel.backgroundColor = .clear
contentView.addSubview(dateLabel)
dateLabel.snp.makeConstraints { make in
self.dateConstraint = make.left.equalTo(hashButton.snp.right).offset(Styles.Sizes.inlineSpacing).constraint
make.centerY.equalToSuperview()
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
layoutContentViewForSafeAreaInsets()
}
// MARK: Private API
@objc func onActor() {
delegate?.didTapActor(cell: self)
}
@objc func onHash() {
delegate?.didTapHash(cell: self)
}
// MARK: Public API
func configure(_ model: IssueStatusEventModel) {
let actorAttributes = [
NSAttributedStringKey.foregroundColor: Styles.Colors.Gray.dark.color,
NSAttributedStringKey.font: Styles.Text.secondaryBold.preferredFont
]
actorButton.setAttributedTitle(NSAttributedString(string: model.actor, attributes: actorAttributes), for: .normal)
let title: String
switch model.status {
case .reopened: title = Constants.Strings.reopened // open event only happens when RE-opening
case .closed: title = Constants.Strings.closed
case .locked: title = Constants.Strings.locked
case .unlocked: title = NSLocalizedString("Unlocked", comment: "")
case .merged: title = Constants.Strings.merged
}
statusButton.setTitle(title, for: .normal)
statusButton.config(pullRequest: model.pullRequest, state: model.status.buttonState)
let hash = model.commitHash?.hashDisplay
hashButton.setTitle(hash, for: .normal)
dateConstraint?.update(offset: hash == nil ? -30 : Styles.Sizes.inlineSpacing)
dateLabel.setText(date: model.date)
}
}