Browse Source

Update UpcomingEventsDataSource.swift

pull/101/head
Abhishek 3 years ago
parent
commit
073de66e68
  1. 15
      Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift

15
Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift

@ -10,19 +10,32 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti
} }
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int { func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int {
if upcomingEvents.isEmpty {
return 1
}
return upcomingEvents.count return upcomingEvents.count
} }
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
let currentEventInfo = upcomingEvents[indexPath.item] if upcomingEvents.isEmpty {
let title = NSLocalizedString("See your next Calendar event here.", comment: "Next Event Label for no Calendar access")
let subtitle = NSLocalizedString("Click here to start.", comment: "Button Title for no Calendar access")
item.setup(title, subtitle, NSColor(red: 97 / 255.0, green: 194 / 255.0, blue: 80 / 255.0, alpha: 1.0))
return 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)
return item return item
} }
func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize { func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
if upcomingEvents.isEmpty {
return NSSize(width: 325, height: 50)
}
let currentEventInfo = upcomingEvents[indexPath.item] let currentEventInfo = upcomingEvents[indexPath.item]
let prefferedSize = avenirLightFont.size(currentEventInfo.event.title, 250, attributes: [NSAttributedString.Key.font: avenirLightFont,]) let prefferedSize = avenirLightFont.size(currentEventInfo.event.title, 250, attributes: [NSAttributedString.Key.font: avenirLightFont,])
return NSSize(width: prefferedSize.width, height: 50) return NSSize(width: prefferedSize.width, height: 50)

Loading…
Cancel
Save