You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.2 KiB

// Copyright © 2015 Abhishek Banthia
import Foundation
class UpcomingEventViewItem: NSCollectionViewItem {
static let reuseIdentifier = NSUserInterfaceItemIdentifier("UpcomingEventViewItem")
3 years ago
3 years ago
@IBOutlet var calendarColorView: NSView!
@IBOutlet var leadingConstraint: NSLayoutConstraint!
@IBOutlet var eventTitleLabel: NSTextField!
@IBOutlet var eventSubtitleButton: NSButton!
3 years ago
@IBOutlet var supplementaryButtonWidthConstraint: NSLayoutConstraint!
3 years ago
@IBOutlet var zoomButton: NSButton!
3 years ago
3 years ago
private var meetingLink: URL?
private weak var panelDelegate: UpcomingEventPanelDelegate?
override func viewDidLoad() {
zoomButton.target = self
zoomButton.action = #selector(zoomButtonAction(_:))
}
func setup(_ title: String,
_ subtitle: String,
_ color: NSColor,
_ meetingURL: URL?,
_ delegate: UpcomingEventPanelDelegate?,
_ isCancelled: Bool) {
3 years ago
if leadingConstraint.constant != 5 {
leadingConstraint.constant = 5
}
calendarColorView.layer?.backgroundColor = color.cgColor
3 years ago
setCalendarButtonTitle(buttonTitle: subtitle)
panelDelegate = delegate
if isCancelled {
let strikethroughString = NSAttributedString(string: title, attributes: [NSAttributedString.Key.strikethroughStyle: NSUnderlineStyle.single.rawValue,
NSAttributedString.Key.strikethroughColor: NSColor.gray])
eventTitleLabel.attributedStringValue = strikethroughString
} else {
eventTitleLabel.stringValue = title
}
3 years ago
if meetingURL != nil {
3 years ago
zoomButton.isHidden = false
3 years ago
meetingLink = meetingURL
zoomButton.image = Themer.shared().videoCallImage()
3 years ago
supplementaryButtonWidthConstraint.constant = 24.0
} else {
zoomButton.image = nil
supplementaryButtonWidthConstraint.constant = 0.0
3 years ago
}
}
3 years ago
3 years ago
func setupUndeterminedState(_ delegate: UpcomingEventPanelDelegate?) {
3 years ago
if leadingConstraint.constant != 10 {
leadingConstraint.constant = 10
}
eventTitleLabel.stringValue = NSLocalizedString("See your next Calendar event here.", comment: "Next Event Label for no Calendar access")
setCalendarButtonTitle(buttonTitle: NSLocalizedString("Click here to start.", comment: "Button Title for no Calendar access"))
3 years ago
calendarColorView.layer?.backgroundColor = NSColor.systemBlue.cgColor
3 years ago
zoomButton.image = Themer.shared().removeImage()
panelDelegate = delegate
}
3 years ago
3 years ago
func setupEmptyState() {
if leadingConstraint.constant != 10 {
leadingConstraint.constant = 10
}
eventTitleLabel.stringValue = NSLocalizedString("No upcoming events for today!", comment: "Next Event Label with no upcoming event")
3 years ago
setCalendarButtonTitle(buttonTitle: NSLocalizedString("Great going.", comment: "Button Title for no upcoming event"))
3 years ago
calendarColorView.layer?.backgroundColor = NSColor.systemGreen.cgColor
zoomButton.image = Themer.shared().removeImage()
}
3 years ago
private func setCalendarButtonTitle(buttonTitle: String) {
let style = NSMutableParagraphStyle()
style.alignment = .left
style.lineBreakMode = .byTruncatingTail
3 years ago
3 years ago
if let boldFont = NSFont(name: "Avenir", size: 11) {
let attributes = [NSAttributedString.Key.foregroundColor: NSColor.gray, NSAttributedString.Key.paragraphStyle: style, NSAttributedString.Key.font: boldFont]
let attributedString = NSAttributedString(string: buttonTitle, attributes: attributes)
eventSubtitleButton.attributedTitle = attributedString
eventSubtitleButton.toolTip = attributedString.string
}
}
override var acceptsFirstResponder: Bool {
return false
}
3 years ago
@IBAction func calendarButtonAction(_ sender: NSButton) {
3 years ago
panelDelegate?.didClickSupplementaryButton(sender)
3 years ago
}
@objc func zoomButtonAction(_: Any) {
if let meetingURL = meetingLink {
NSWorkspace.shared.open(meetingURL)
} else {
3 years ago
panelDelegate?.didRemoveCalendarView()
3 years ago
}
}
}