You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.3 KiB

// Copyright © 2015 Abhishek Banthia
import Foundation
class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout {
private var upcomingEvents: [EventInfo] = []
private var eventCenter: EventCenter!
3 years ago
private weak var delegate: UpcomingEventPanelDelegate?
3 years ago
init(_ panelDelegate: UpcomingEventPanelDelegate?, _ center: EventCenter) {
3 years ago
super.init()
delegate = panelDelegate
eventCenter = center
3 years ago
}
3 years ago
func updateEventsDataSource(_ events: [EventInfo]) {
upcomingEvents = events
}
3 years ago
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int {
3 years ago
if eventCenter.calendarAccessDenied() || eventCenter.calendarAccessNotDetermined() || upcomingEvents.isEmpty {
return 1
}
return upcomingEvents.count
}
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItem(withIdentifier: UpcomingEventViewItem.reuseIdentifier, for: indexPath) as! UpcomingEventViewItem
if eventCenter.calendarAccessNotDetermined() {
3 years ago
item.setupUndeterminedState(delegate)
return item
}
3 years ago
if upcomingEvents.isEmpty {
item.setupEmptyState()
return item
}
3 years ago
let currentEventInfo = upcomingEvents[indexPath.item]
let upcomingEventSubtitle = currentEventInfo.isAllDay ? "All-Day" : currentEventInfo.metadataForMeeting()
3 years ago
item.setup(currentEventInfo.event.title, upcomingEventSubtitle, currentEventInfo.event.calendar.color,
currentEventInfo.meetingURL, delegate)
return item
}
3 years ago
func collectionView(_ collectionView: NSCollectionView, layout _: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
3 years ago
if upcomingEvents.isEmpty || eventCenter.calendarAccessNotDetermined() {
3 years ago
return NSSize(width: collectionView.frame.width - 20, height: 50)
}
3 years ago
let currentEventInfo = upcomingEvents[indexPath.item]
let attributedString = NSAttributedString(string: currentEventInfo.event.title, attributes: [NSAttributedString.Key.font : avenirLightFont])
return NSSize(width: attributedString.size().width + 60, height: 50)
}
}