Browse Source

Update UpcomingEventViewItem.swift

pull/101/head
Abhishek 3 years ago
parent
commit
4e62a1722a
  1. 91
      Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift

91
Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift

@ -12,6 +12,8 @@ class UpcomingEventViewItem: NSCollectionViewItem {
@IBOutlet var supplementaryButtonWidthConstraint: NSLayoutConstraint! @IBOutlet var supplementaryButtonWidthConstraint: NSLayoutConstraint!
@IBOutlet var zoomButton: NSButton! @IBOutlet var zoomButton: NSButton!
private static let SupplementaryButtonWidth: CGFloat = 24.0
private static let EventLeadingConstraint: CGFloat = 10.0
private var meetingLink: URL? private var meetingLink: URL?
private weak var panelDelegate: UpcomingEventPanelDelegate? private weak var panelDelegate: UpcomingEventPanelDelegate?
@ -20,62 +22,84 @@ class UpcomingEventViewItem: NSCollectionViewItem {
zoomButton.action = #selector(zoomButtonAction(_:)) zoomButton.action = #selector(zoomButtonAction(_:))
} }
override func prepareForReuse() {
zoomButton.image = nil
eventTitleLabel.stringValue = ""
eventSubtitleButton.stringValue = ""
}
override var acceptsFirstResponder: Bool {
return false
}
// MARK: Setup UI
func setup(_ title: String, func setup(_ title: String,
_ subtitle: String, _ subtitle: String,
_ color: NSColor, _ color: NSColor,
_ meetingURL: URL?, _ link: URL?,
_ delegate: UpcomingEventPanelDelegate?, _ delegate: UpcomingEventPanelDelegate?,
_ isCancelled: Bool) { _ isCancelled: Bool) {
if leadingConstraint.constant != 5 { if leadingConstraint.constant != UpcomingEventViewItem.EventLeadingConstraint / 2 {
leadingConstraint.constant = 5 leadingConstraint.animator().constant = UpcomingEventViewItem.EventLeadingConstraint / 2
} }
calendarColorView.layer?.backgroundColor = color.cgColor
setCalendarButtonTitle(buttonTitle: subtitle)
panelDelegate = delegate panelDelegate = delegate
meetingLink = link
if isCancelled { setupLabels(title, isCancelled)
let strikethroughString = NSAttributedString(string: title, attributes: [NSAttributedString.Key.strikethroughStyle: NSUnderlineStyle.single.rawValue, setupSupplementaryButton(link)
NSAttributedString.Key.strikethroughColor: NSColor.gray]) setCalendarButtonTitle(buttonTitle: subtitle)
eventTitleLabel.attributedStringValue = strikethroughString calendarColorView.layer?.backgroundColor = color.cgColor
} else {
eventTitleLabel.stringValue = title
} }
private func setupLabels(_ title: String, _ cancellationState: Bool) {
let attributes: [NSAttributedString.Key: Any] = cancellationState ? [NSAttributedString.Key.strikethroughStyle: NSUnderlineStyle.single.rawValue,
NSAttributedString.Key.strikethroughColor: NSColor.gray] : [:]
let attributedString = NSAttributedString(string: title, attributes: attributes)
eventTitleLabel.attributedStringValue = attributedString
eventTitleLabel.toolTip = title eventTitleLabel.toolTip = title
}
if meetingURL != nil { private func setupSupplementaryButton(_ meetingURL: URL?) {
zoomButton.isHidden = false guard meetingURL != nil else {
meetingLink = meetingURL
zoomButton.image = Themer.shared().videoCallImage()
supplementaryButtonWidthConstraint.constant = 24.0
} else {
zoomButton.image = nil zoomButton.image = nil
supplementaryButtonWidthConstraint.constant = 0.0 supplementaryButtonWidthConstraint.constant = 0.0
} return
} }
func setupUndeterminedState(_ delegate: UpcomingEventPanelDelegate?) { zoomButton.isHidden = false
if leadingConstraint.constant != 10 { zoomButton.image = Themer.shared().videoCallImage()
leadingConstraint.constant = 10
if supplementaryButtonWidthConstraint.constant != UpcomingEventViewItem.SupplementaryButtonWidth {
supplementaryButtonWidthConstraint.constant = UpcomingEventViewItem.SupplementaryButtonWidth
}
} }
eventTitleLabel.stringValue = NSLocalizedString("See your next Calendar event here.", comment: "Next Event Label for no Calendar access") func setupUndeterminedState(_ delegate: UpcomingEventPanelDelegate?) {
setCalendarButtonTitle(buttonTitle: NSLocalizedString("Click here to start.", comment: "Button Title for no Calendar access"))
calendarColorView.layer?.backgroundColor = NSColor.systemBlue.cgColor
zoomButton.image = Themer.shared().removeImage()
panelDelegate = delegate panelDelegate = delegate
setAlternateState(NSLocalizedString("See your next Calendar event here.", comment: "Next Event Label for no Calendar access"),
NSLocalizedString("Click here to start.", comment: "Button Title for no Calendar access"),
NSColor.systemBlue,
Themer.shared().removeImage())
} }
func setupEmptyState() { func setupEmptyState() {
if leadingConstraint.constant != 10 { setAlternateState(NSLocalizedString("No upcoming events for today!", comment: "Next Event Label with no upcoming event"),
leadingConstraint.constant = 10 NSLocalizedString("Great going.", comment: "Button Title for no upcoming event"),
NSColor.systemGreen,
nil)
} }
eventTitleLabel.stringValue = NSLocalizedString("No upcoming events for today!", comment: "Next Event Label with no upcoming event") private func setAlternateState(_ title: String, _ buttonTitle: String, _ color: NSColor, _ image: NSImage? = nil) {
setCalendarButtonTitle(buttonTitle: NSLocalizedString("Great going.", comment: "Button Title for no upcoming event")) if leadingConstraint.constant != UpcomingEventViewItem.EventLeadingConstraint {
calendarColorView.layer?.backgroundColor = NSColor.systemGreen.cgColor leadingConstraint.animator().constant = UpcomingEventViewItem.EventLeadingConstraint
zoomButton.image = Themer.shared().removeImage() }
eventTitleLabel.stringValue = title
setCalendarButtonTitle(buttonTitle: buttonTitle)
calendarColorView.layer?.backgroundColor = color.cgColor
zoomButton.image = image
} }
private func setCalendarButtonTitle(buttonTitle: String) { private func setCalendarButtonTitle(buttonTitle: String) {
@ -85,16 +109,13 @@ class UpcomingEventViewItem: NSCollectionViewItem {
if let boldFont = NSFont(name: "Avenir", size: 11) { if let boldFont = NSFont(name: "Avenir", size: 11) {
let attributes = [NSAttributedString.Key.foregroundColor: NSColor.gray, NSAttributedString.Key.paragraphStyle: style, NSAttributedString.Key.font: boldFont] let attributes = [NSAttributedString.Key.foregroundColor: NSColor.gray, NSAttributedString.Key.paragraphStyle: style, NSAttributedString.Key.font: boldFont]
let attributedString = NSAttributedString(string: buttonTitle, attributes: attributes) let attributedString = NSAttributedString(string: buttonTitle, attributes: attributes)
eventSubtitleButton.attributedTitle = attributedString eventSubtitleButton.attributedTitle = attributedString
eventSubtitleButton.toolTip = attributedString.string eventSubtitleButton.toolTip = attributedString.string
} }
} }
override var acceptsFirstResponder: Bool { // MARK: Button Actions
return false
}
@IBAction func calendarButtonAction(_ sender: NSButton) { @IBAction func calendarButtonAction(_ sender: NSButton) {
panelDelegate?.didClickSupplementaryButton(sender) panelDelegate?.didClickSupplementaryButton(sender)

Loading…
Cancel
Save