Browse Source

Merge branch 'master' of https://github.com/n0shake/Clocker

pull/101/head
Abhishek 3 years ago
parent
commit
b8144218b7
  1. 15
      Clocker/Events and Reminders/CalendarHandler.swift
  2. 2
      Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift
  3. 13
      Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift
  4. 15
      Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift

15
Clocker/Events and Reminders/CalendarHandler.swift

@ -197,8 +197,9 @@ extension EventCenter {
return nil 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 { return relevantEvents.filter {
$0.event.startDate.timeIntervalSinceNow > -300 $0.event.startDate.timeIntervalSinceNow > -300
} }
@ -486,12 +487,20 @@ struct EventInfo {
let timeIntervalSinceNowForMeeting = event.startDate.timeIntervalSinceNow let timeIntervalSinceNowForMeeting = event.startDate.timeIntervalSinceNow
if timeIntervalSinceNowForMeeting < 0, timeIntervalSinceNowForMeeting > -300 { if timeIntervalSinceNowForMeeting < 0, timeIntervalSinceNowForMeeting > -300 {
return "started \(event.startDate.shortTimeAgoSinceNow) ago." return "started \(event.startDate.shortTimeAgoSinceNow) ago."
} else { } else if event.startDate.isToday {
let timeSince = Date().timeAgo(since: event.startDate) let timeSince = Date().timeAgo(since: event.startDate)
let withoutAn = timeSince.replacingOccurrences(of: "an", with: CLEmptyString) let withoutAn = timeSince.replacingOccurrences(of: "an", with: CLEmptyString)
let withoutAgo = withoutAn.replacingOccurrences(of: "ago", 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 "in \(withoutAgo.lowercased())"
} }
return "Error"
} }
} }

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

@ -17,7 +17,7 @@ protocol UpcomingEventPanelDelegate: AnyObject {
extension ParentPanelController { extension ParentPanelController {
func setupUpcomingEventViewCollectionViewIfNeccesary() { func setupUpcomingEventViewCollectionViewIfNeccesary() {
if upcomingEventCollectionView != nil { if upcomingEventCollectionView != nil {
upcomingEventsDataSource = UpcomingEventsDataSource(self) upcomingEventsDataSource = UpcomingEventsDataSource(self, EventCenter.sharedCenter())
upcomingEventCollectionView.enclosingScrollView?.scrollerInsets = NSEdgeInsetsZero upcomingEventCollectionView.enclosingScrollView?.scrollerInsets = NSEdgeInsetsZero
upcomingEventCollectionView.enclosingScrollView?.backgroundColor = NSColor.clear upcomingEventCollectionView.enclosingScrollView?.backgroundColor = NSColor.clear
upcomingEventCollectionView.setAccessibility("UpcomingEventCollectionView") upcomingEventCollectionView.setAccessibility("UpcomingEventCollectionView")

13
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") 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")) 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() zoomButton.image = Themer.shared().removeImage()
panelDelegate = delegate 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) { private func setCalendarButtonTitle(buttonTitle: String) {
let style = NSMutableParagraphStyle() let style = NSMutableParagraphStyle()
style.alignment = .left style.alignment = .left

15
Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift

@ -4,11 +4,13 @@ import Foundation
class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout { class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout {
private var upcomingEvents: [EventInfo] = [] private var upcomingEvents: [EventInfo] = []
private var eventCenter: EventCenter!
private weak var delegate: UpcomingEventPanelDelegate? private weak var delegate: UpcomingEventPanelDelegate?
init(_ panelDelegate: UpcomingEventPanelDelegate?) { init(_ panelDelegate: UpcomingEventPanelDelegate?, _ center: EventCenter) {
super.init() super.init()
delegate = panelDelegate delegate = panelDelegate
eventCenter = center
} }
func updateEventsDataSource(_ events: [EventInfo]) { func updateEventsDataSource(_ events: [EventInfo]) {
@ -16,7 +18,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti
} }
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int { func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int {
if upcomingEvents.isEmpty { if eventCenter.calendarAccessDenied() || eventCenter.calendarAccessNotDetermined() || upcomingEvents.isEmpty {
return 1 return 1
} }
return upcomingEvents.count return upcomingEvents.count
@ -24,11 +26,16 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem { func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItem(withIdentifier: UpcomingEventViewItem.reuseIdentifier, for: indexPath) as! UpcomingEventViewItem let item = collectionView.makeItem(withIdentifier: UpcomingEventViewItem.reuseIdentifier, for: indexPath) as! UpcomingEventViewItem
if upcomingEvents.isEmpty { if eventCenter.calendarAccessNotDetermined() {
item.setupUndeterminedState(delegate) item.setupUndeterminedState(delegate)
return item return item
} }
if upcomingEvents.isEmpty {
item.setupEmptyState()
return item
}
let currentEventInfo = upcomingEvents[indexPath.item] let currentEventInfo = upcomingEvents[indexPath.item]
let upcomingEventSubtitle = currentEventInfo.isAllDay ? "All-Day" : currentEventInfo.metadataForMeeting() 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,
@ -37,7 +44,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti
} }
func collectionView(_ collectionView: NSCollectionView, layout _: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize { 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) return NSSize(width: collectionView.frame.width - 20, height: 50)
} }

Loading…
Cancel
Save