diff --git a/Clocker/Events and Reminders/CalendarHandler.swift b/Clocker/Events and Reminders/CalendarHandler.swift index 57ab3b8..7cbd564 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" } } 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 cbf151a..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) + 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 ea2c2c1..7a3c2a4 100644 --- a/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift +++ b/Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift @@ -46,11 +46,22 @@ 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() style.alignment = .left diff --git a/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift b/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift index be3c033..85cad90 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,11 +26,16 @@ 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 { + if eventCenter.calendarAccessNotDetermined() { item.setupUndeterminedState(delegate) return item } + if upcomingEvents.isEmpty { + item.setupEmptyState() + 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, @@ -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) }