From 6c45eff0666906f030aeb7e75760126781240075 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 9 Aug 2021 22:26:26 -0500 Subject: [PATCH 1/5] Empty state. --- .../Upcoming Events/UpcomingEventViewItem.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift b/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift index ea2c2c1..1906664 100644 --- a/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift +++ b/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift @@ -46,10 +46,21 @@ class UpcomingEventViewItem: NSCollectionViewItem { 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 + calendarColorView.layer?.backgroundColor = NSColor.systemBlue.cgColor zoomButton.image = Themer.shared().removeImage() panelDelegate = delegate } + + 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") + setCalendarButtonTitle(buttonTitle: NSLocalizedString("Inbox Zero!", comment: "Button Title for no upcoming event")) + calendarColorView.layer?.backgroundColor = NSColor.systemGreen.cgColor + zoomButton.image = Themer.shared().removeImage() + } private func setCalendarButtonTitle(buttonTitle: String) { let style = NSMutableParagraphStyle() From 8e40e4a99b37c1722b0a2909f4ee5857581df6c0 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 9 Aug 2021 22:27:07 -0500 Subject: [PATCH 2/5] Update UpcomingEventsDataSource.swift --- .../UpcomingEventsDataSource.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift b/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift index 9cfd543..ee5c68b 100644 --- a/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift +++ b/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift @@ -4,11 +4,13 @@ import Foundation class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout { private var upcomingEvents: [EventInfo] = [] + private var eventCenter: EventCenter! private weak var delegate: UpcomingEventPanelDelegate? - init(_ panelDelegate: UpcomingEventPanelDelegate?) { + init(_ panelDelegate: UpcomingEventPanelDelegate?, _ center: EventCenter) { super.init() delegate = panelDelegate + eventCenter = center } func updateEventsDataSource(_ events: [EventInfo]) { @@ -16,7 +18,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti } func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int { - if upcomingEvents.isEmpty { + if eventCenter.calendarAccessDenied() || eventCenter.calendarAccessNotDetermined() || upcomingEvents.isEmpty { return 1 } return upcomingEvents.count @@ -24,8 +26,13 @@ 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 eventCenter.calendarAccessNotDetermined() { + item.setupUndeterminedState(delegate) + return item + } + if upcomingEvents.isEmpty { - item.setupUndeterminedState(delegate) + item.setupEmptyState() return item } @@ -37,7 +44,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti } func collectionView(_ collectionView: NSCollectionView, layout _: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize { - if upcomingEvents.isEmpty { + if upcomingEvents.isEmpty || eventCenter.calendarAccessNotDetermined() { return NSSize(width: collectionView.frame.width - 20, height: 50) } From 21f71eb06f11fd6f28683d70b9dba7628c03115e Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 9 Aug 2021 22:27:12 -0500 Subject: [PATCH 3/5] Update ParentPanelController+UpcomingEvents.swift --- .../Upcoming Events/ParentPanelController+UpcomingEvents.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift b/Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift index cbf151a..fc5dcf7 100644 --- a/Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift +++ b/Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift @@ -17,7 +17,7 @@ protocol UpcomingEventPanelDelegate: AnyObject { extension ParentPanelController { func setupUpcomingEventViewCollectionViewIfNeccesary() { if upcomingEventCollectionView != nil { - upcomingEventsDataSource = UpcomingEventsDataSource(self) + upcomingEventsDataSource = UpcomingEventsDataSource(self, EventCenter.sharedCenter()) upcomingEventCollectionView.enclosingScrollView?.scrollerInsets = NSEdgeInsetsZero upcomingEventCollectionView.enclosingScrollView?.backgroundColor = NSColor.clear upcomingEventCollectionView.setAccessibility("UpcomingEventCollectionView") From e793ae3360d76b601bc4145d3a1c738caac13920 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 9 Aug 2021 22:30:39 -0500 Subject: [PATCH 4/5] Update CalendarHandler.swift --- .../Events and Reminders/CalendarHandler.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Clocker/Events and Reminders/CalendarHandler.swift b/Clocker/Events and Reminders/CalendarHandler.swift index 57ab3b8..6bcc562 100644 --- a/Clocker/Events and Reminders/CalendarHandler.swift +++ b/Clocker/Events and Reminders/CalendarHandler.swift @@ -197,8 +197,9 @@ extension EventCenter { return nil } - let relevantEvents = filteredEvents[autoupdatingCalendar.startOfDay(for: Date())] ?? [] - + let todayEvents = filteredEvents[autoupdatingCalendar.startOfDay(for: Date())] ?? [] + let tomorrowEvents = filteredEvents[autoupdatingCalendar.startOfDay(for: Date().addingTimeInterval(86400))] ?? [] + let relevantEvents = todayEvents + tomorrowEvents return relevantEvents.filter { $0.event.startDate.timeIntervalSinceNow > -300 } @@ -486,12 +487,20 @@ struct EventInfo { let timeIntervalSinceNowForMeeting = event.startDate.timeIntervalSinceNow if timeIntervalSinceNowForMeeting < 0, timeIntervalSinceNowForMeeting > -300 { return "started \(event.startDate.shortTimeAgoSinceNow) ago." - } else { + } else if event.startDate.isToday { let timeSince = Date().timeAgo(since: event.startDate) let withoutAn = timeSince.replacingOccurrences(of: "an", with: CLEmptyString) let withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString) return "in \(withoutAgo.lowercased())" + } else if event.startDate.isTomorrow { + let timeSince = event.startDate.shortTimeAgoSinceNow + let withoutAn = timeSince.replacingOccurrences(of: "an", with: CLEmptyString) + let withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString) + + return "in \(withoutAgo.lowercased())" } + + return "Error" } } From 6eab595a33b2ee1eb46483faa1129ce9a0926e0c Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 9 Aug 2021 22:37:26 -0500 Subject: [PATCH 5/5] Formatting. --- Clocker/Events and Reminders/CalendarHandler.swift | 12 ++++++------ Clocker/Panel/ParentPanelController.swift | 2 +- .../ParentPanelController+UpcomingEvents.swift | 2 +- .../Upcoming Events/UpcomingEventViewItem.swift | 2 +- .../Upcoming Events/UpcomingEventsDataSource.swift | 12 ++++++------ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Clocker/Events and Reminders/CalendarHandler.swift b/Clocker/Events and Reminders/CalendarHandler.swift index 6bcc562..7cbd564 100644 --- a/Clocker/Events and Reminders/CalendarHandler.swift +++ b/Clocker/Events and Reminders/CalendarHandler.swift @@ -494,13 +494,13 @@ struct EventInfo { return "in \(withoutAgo.lowercased())" } else if event.startDate.isTomorrow { - let timeSince = event.startDate.shortTimeAgoSinceNow - let withoutAn = timeSince.replacingOccurrences(of: "an", with: CLEmptyString) - let withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString) + let timeSince = event.startDate.shortTimeAgoSinceNow + let withoutAn = timeSince.replacingOccurrences(of: "an", with: CLEmptyString) + let withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString) - return "in \(withoutAgo.lowercased())" + return "in \(withoutAgo.lowercased())" } - - return "Error" + + return "Error" } } diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 4cad4bb..fdc1641 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -747,7 +747,7 @@ class ParentPanelController: NSWindowController { @IBAction func calendarButtonAction(_ sender: NSButton) { if sender.title == NSLocalizedString("Click here to start.", - comment: "Button Title for no Calendar access") { + comment: "Button Title for no Calendar access") { showPermissionsWindow() } else { retrieveCalendarEvents() diff --git a/Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift b/Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift index fc5dcf7..adcb5c0 100644 --- a/Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift +++ b/Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift @@ -17,7 +17,7 @@ protocol UpcomingEventPanelDelegate: AnyObject { extension ParentPanelController { func setupUpcomingEventViewCollectionViewIfNeccesary() { if upcomingEventCollectionView != nil { - upcomingEventsDataSource = UpcomingEventsDataSource(self, EventCenter.sharedCenter()) + upcomingEventsDataSource = UpcomingEventsDataSource(self, EventCenter.sharedCenter()) upcomingEventCollectionView.enclosingScrollView?.scrollerInsets = NSEdgeInsetsZero upcomingEventCollectionView.enclosingScrollView?.backgroundColor = NSColor.clear upcomingEventCollectionView.setAccessibility("UpcomingEventCollectionView") diff --git a/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift b/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift index 1906664..7a3c2a4 100644 --- a/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift +++ b/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift @@ -50,7 +50,7 @@ class UpcomingEventViewItem: NSCollectionViewItem { zoomButton.image = Themer.shared().removeImage() panelDelegate = delegate } - + func setupEmptyState() { if leadingConstraint.constant != 10 { leadingConstraint.constant = 10 diff --git a/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift b/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift index ee5c68b..ab9bbff 100644 --- a/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift +++ b/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift @@ -7,7 +7,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti private var eventCenter: EventCenter! private weak var delegate: UpcomingEventPanelDelegate? - init(_ panelDelegate: UpcomingEventPanelDelegate?, _ center: EventCenter) { + init(_ panelDelegate: UpcomingEventPanelDelegate?, _ center: EventCenter) { super.init() delegate = panelDelegate eventCenter = center @@ -18,7 +18,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti } func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int { - if eventCenter.calendarAccessDenied() || eventCenter.calendarAccessNotDetermined() || upcomingEvents.isEmpty { + if eventCenter.calendarAccessDenied() || eventCenter.calendarAccessNotDetermined() || upcomingEvents.isEmpty { return 1 } return upcomingEvents.count @@ -27,10 +27,10 @@ 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 eventCenter.calendarAccessNotDetermined() { - item.setupUndeterminedState(delegate) - return item + item.setupUndeterminedState(delegate) + return item } - + if upcomingEvents.isEmpty { item.setupEmptyState() return item @@ -44,7 +44,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti } func collectionView(_ collectionView: NSCollectionView, layout _: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize { - if upcomingEvents.isEmpty || eventCenter.calendarAccessNotDetermined() { + if upcomingEvents.isEmpty || eventCenter.calendarAccessNotDetermined() { return NSSize(width: collectionView.frame.width - 20, height: 50) }