Browse Source

Finishing.

pull/101/head
Abhishek 3 years ago
parent
commit
053712cab4
  1. 10
      Clocker/Panel/ParentPanelController.swift
  2. 18
      Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift
  3. 79
      Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift
  4. 33
      Clocker/Panel/Upcoming Events/UpcomingEventViewItem.xib
  5. 29
      Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift

10
Clocker/Panel/ParentPanelController.swift

@ -99,7 +99,7 @@ class ParentPanelController: NSWindowController {
// Upcoming Events
@IBOutlet var upcomingEventCollectionView: NSCollectionView!
@IBOutlet var upcomingEventContainerView: NSView!
public let upcomingEventsDataSource = UpcomingEventsDataSource()
public var upcomingEventsDataSource: UpcomingEventsDataSource!
var defaultPreferences: [Data] {
return DataStore.shared().timezones()
@ -736,7 +736,13 @@ class ParentPanelController: NSWindowController {
func removeUpcomingEventView() {
OperationQueue.main.addOperation {
if self.stackView.arrangedSubviews.contains(self.upcomingEventView!), self.upcomingEventView?.isHidden == false {
if self.upcomingEventCollectionView != nil {
if self.stackView.arrangedSubviews.contains(self.upcomingEventContainerView!), self.upcomingEventContainerView?.isHidden == false {
self.upcomingEventContainerView?.isHidden = true
UserDefaults.standard.set("NO", forKey: CLShowUpcomingEventView)
Logger.log(object: ["Removed": "YES"], for: "Removed Upcoming Event View")
}
} else if self.stackView.arrangedSubviews.contains(self.upcomingEventView!), self.upcomingEventView?.isHidden == false {
self.upcomingEventView?.isHidden = true
UserDefaults.standard.set("NO", forKey: CLShowUpcomingEventView)
Logger.log(object: ["Removed": "YES"], for: "Removed Upcoming Event View")

18
Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift

@ -9,10 +9,16 @@ var avenirLightFont: NSFont {
return NSFont.systemFont(ofSize: 12)
}
protocol UpcomingEventPanelDelegate: AnyObject {
func didRemoveCalendarView()
func didClickSupplementaryButton(_ sender: NSButton)
}
extension ParentPanelController {
func setupUpcomingEventViewCollectionViewIfNeccesary() {
if upcomingEventCollectionView != nil {
upcomingEventCollectionView.enclosingScrollView?.scrollerInsets = NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
upcomingEventsDataSource = UpcomingEventsDataSource(self)
upcomingEventCollectionView.enclosingScrollView?.scrollerInsets = NSEdgeInsetsZero
upcomingEventCollectionView.enclosingScrollView?.backgroundColor = NSColor.clear
upcomingEventCollectionView.setAccessibility("UpcomingEventCollectionView")
upcomingEventCollectionView.dataSource = upcomingEventsDataSource
@ -20,3 +26,13 @@ extension ParentPanelController {
}
}
}
extension ParentPanelController: UpcomingEventPanelDelegate {
func didRemoveCalendarView() {
removeUpcomingEventView()
}
func didClickSupplementaryButton(_ sender: NSButton) {
calendarButtonAction(sender)
}
}

79
Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift

@ -4,19 +4,80 @@ import Foundation
class UpcomingEventViewItem: NSCollectionViewItem {
static let reuseIdentifier = NSUserInterfaceItemIdentifier("UpcomingEventViewItem")
@IBOutlet weak var calendarColorView: NSView!
@IBOutlet weak var eventTitleLabel: NSTextField!
@IBOutlet weak var eventSubtitleLabel: NSButton!
func setup(_ title: String, _ subtitle: String, _ color: NSColor) {
@IBOutlet var calendarColorView: NSView!
@IBOutlet var leadingConstraint: NSLayoutConstraint!
@IBOutlet var eventTitleLabel: NSTextField!
@IBOutlet var eventSubtitleButton: NSButton!
@IBOutlet var zoomButton: NSButton!
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?) {
if leadingConstraint.constant != 5 {
leadingConstraint.constant = 5
}
calendarColorView.layer?.backgroundColor = color.cgColor
eventTitleLabel.stringValue = title
eventSubtitleLabel.stringValue = subtitle
setCalendarButtonTitle(buttonTitle: subtitle)
panelDelegate = delegate
if meetingURL != nil {
meetingLink = meetingURL
zoomButton.image = Themer.shared().videoCallImage()
}
}
func setupUndeterminedState(_ delegate: UpcomingEventPanelDelegate?) {
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"))
calendarColorView.layer?.backgroundColor = NSColor.blue.cgColor
zoomButton.image = Themer.shared().removeImage()
panelDelegate = delegate
}
private func setCalendarButtonTitle(buttonTitle: String) {
let style = NSMutableParagraphStyle()
style.alignment = .left
style.lineBreakMode = .byTruncatingTail
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
}
@IBAction func calendarButtonAction(_ sender: NSButton) {
panelDelegate?.didClickSupplementaryButton(sender)
}
@objc func zoomButtonAction(_: Any) {
if let meetingURL = meetingLink {
NSWorkspace.shared.open(meetingURL)
} else {
panelDelegate?.didRemoveCalendarView()
}
}
}

33
Clocker/Panel/Upcoming Events/UpcomingEventViewItem.xib

@ -17,7 +17,7 @@
<rect key="frame" x="0.0" y="0.0" width="250" height="75"/>
<subviews>
<button focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Khp-8n-4FA">
<rect key="frame" x="16" y="21" width="232" height="18"/>
<rect key="frame" x="16" y="21" width="198" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="asu-Dd-XhW"/>
</constraints>
@ -25,6 +25,9 @@
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" size="10" name="Avenir-Heavy"/>
</buttonCell>
<connections>
<action selector="calendarButtonAction:" target="p0M-E4-898" id="Gua-lA-sNh"/>
</connections>
</button>
<customView wantsLayer="YES" focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="Bbu-oG-vAb">
<rect key="frame" x="5" y="21" width="2" height="34"/>
@ -34,7 +37,7 @@
</constraints>
</customView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fTt-gC-72b">
<rect key="frame" x="15" y="31" width="235" height="24"/>
<rect key="frame" x="15" y="33" width="201" height="24"/>
<constraints>
<constraint firstAttribute="height" constant="24" id="BA4-1v-xiZ"/>
</constraints>
@ -44,15 +47,28 @@
<color key="backgroundColor" red="1" green="0.5" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
</textFieldCell>
</textField>
<button translatesAutoresizingMaskIntoConstraints="NO" id="qRe-Ao-1fr">
<rect key="frame" x="216" y="26" width="24" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="24" id="ZRs-Vt-FOM"/>
<constraint firstAttribute="height" constant="24" id="ouc-t4-DO2"/>
</constraints>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="Appearance" imagePosition="only" alignment="center" imageScaling="proportionallyUpOrDown" inset="2" id="8Sv-kp-Zff">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
<constraints>
<constraint firstItem="fTt-gC-72b" firstAttribute="top" secondItem="Bbu-oG-vAb" secondAttribute="top" id="FeN-R0-t1A"/>
<constraint firstItem="qRe-Ao-1fr" firstAttribute="leading" secondItem="fTt-gC-72b" secondAttribute="trailing" constant="2" id="161-lb-rqc"/>
<constraint firstItem="fTt-gC-72b" firstAttribute="top" secondItem="Bbu-oG-vAb" secondAttribute="top" constant="-2" id="FeN-R0-t1A"/>
<constraint firstItem="Khp-8n-4FA" firstAttribute="bottom" secondItem="Bbu-oG-vAb" secondAttribute="bottom" id="LQD-54-bUh"/>
<constraint firstItem="Bbu-oG-vAb" firstAttribute="leading" secondItem="aM6-TI-1os" secondAttribute="leading" constant="5" id="Myg-8W-znN"/>
<constraint firstAttribute="trailing" secondItem="qRe-Ao-1fr" secondAttribute="trailing" constant="10" id="Myk-Ff-8WP"/>
<constraint firstItem="Khp-8n-4FA" firstAttribute="trailing" secondItem="fTt-gC-72b" secondAttribute="trailing" id="URW-gt-WbF"/>
<constraint firstAttribute="trailing" secondItem="fTt-gC-72b" secondAttribute="trailing" constant="2" id="UmL-0o-BVG"/>
<constraint firstItem="Khp-8n-4FA" firstAttribute="leading" secondItem="fTt-gC-72b" secondAttribute="leading" constant="-1" id="VyL-Kt-2aT"/>
<constraint firstItem="fTt-gC-72b" firstAttribute="leading" secondItem="Bbu-oG-vAb" secondAttribute="trailing" constant="10" id="arv-Oe-yih"/>
<constraint firstItem="qRe-Ao-1fr" firstAttribute="centerY" secondItem="aM6-TI-1os" secondAttribute="centerY" id="vdC-gb-1wa"/>
<constraint firstItem="Bbu-oG-vAb" firstAttribute="centerY" secondItem="aM6-TI-1os" secondAttribute="centerY" id="wkl-Vo-0kU"/>
</constraints>
</customView>
@ -63,15 +79,20 @@
<constraint firstAttribute="bottom" secondItem="aM6-TI-1os" secondAttribute="bottom" id="DmC-7T-lrT"/>
<constraint firstAttribute="trailing" secondItem="aM6-TI-1os" secondAttribute="trailing" id="aCZ-sV-Mnd"/>
</constraints>
<point key="canvasLocation" x="147" y="239"/>
<point key="canvasLocation" x="147" y="238.5"/>
</customView>
<customObject id="p0M-E4-898" customClass="UpcomingEventViewItem" customModule="Clocker" customModuleProvider="target">
<connections>
<outlet property="calendarColorView" destination="Bbu-oG-vAb" id="tBe-V1-qmC"/>
<outlet property="eventSubtitleLabel" destination="Khp-8n-4FA" id="mXV-EZ-2AW"/>
<outlet property="eventSubtitleButton" destination="Khp-8n-4FA" id="mXV-EZ-2AW"/>
<outlet property="eventTitleLabel" destination="fTt-gC-72b" id="bOh-LO-tiH"/>
<outlet property="leadingConstraint" destination="Myg-8W-znN" id="OUR-Na-THS"/>
<outlet property="view" destination="Hz6-mo-xeY" id="9S0-wg-csq"/>
<outlet property="zoomButton" destination="qRe-Ao-1fr" id="0IC-Fx-l3Q"/>
</connections>
</customObject>
</objects>
<resources>
<image name="Appearance" width="350" height="350"/>
</resources>
</document>

29
Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift

@ -4,11 +4,17 @@ import Foundation
class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout {
private var upcomingEvents: [EventInfo] = []
private weak var delegate: UpcomingEventPanelDelegate?
init(_ panelDelegate: UpcomingEventPanelDelegate?) {
super.init()
delegate = panelDelegate
}
func updateEventsDataSource(_ events: [EventInfo]) {
upcomingEvents = events
}
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int {
if upcomingEvents.isEmpty {
return 1
@ -19,25 +25,24 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItem(withIdentifier: UpcomingEventViewItem.reuseIdentifier, for: indexPath) as! UpcomingEventViewItem
if upcomingEvents.isEmpty {
let title = NSLocalizedString("See your next Calendar event here.", comment: "Next Event Label for no Calendar access")
let subtitle = NSLocalizedString("Click here to start.", comment: "Button Title for no Calendar access")
item.setup(title, subtitle, NSColor(red: 97 / 255.0, green: 194 / 255.0, blue: 80 / 255.0, alpha: 1.0))
item.setupUndeterminedState(delegate)
return item
}
let currentEventInfo = upcomingEvents[indexPath.item]
let upcomingEventSubtitle = currentEventInfo.isAllDay ? "All-Day" : currentEventInfo.metadataForMeeting()
item.setup(currentEventInfo.event.title, upcomingEventSubtitle, currentEventInfo.event.calendar.color)
item.setup(currentEventInfo.event.title, upcomingEventSubtitle, currentEventInfo.event.calendar.color,
currentEventInfo.meetingURL, delegate)
return item
}
func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
func collectionView(_ collectionView: NSCollectionView, layout _: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
if upcomingEvents.isEmpty {
return NSSize(width: 325, height: 50)
return NSSize(width: collectionView.frame.width - 20, height: 50)
}
let currentEventInfo = upcomingEvents[indexPath.item]
let prefferedSize = avenirLightFont.size(currentEventInfo.event.title, 250, attributes: [NSAttributedString.Key.font: avenirLightFont,])
let prefferedSize = avenirLightFont.size(currentEventInfo.event.title, 250, attributes: [NSAttributedString.Key.font: avenirLightFont])
return NSSize(width: prefferedSize.width, height: 50)
}
}

Loading…
Cancel
Save