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/ParentPanelController.swift
  3. 2
      Clocker/Panel/Upcoming Events/ParentPanelController+UpcomingEvents.swift
  4. 13
      Clocker/Panel/Upcoming Events/UpcomingEventViewItem.swift
  5. 15
      Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift

15
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"
}
}

2
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()

2
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")

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")
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

15
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)
}

Loading…
Cancel
Save